4
How to create/modify a variable within a if
and be able to access it without having to set it in global mode/scope. I am working on a Lua file similar to this scheme:
if verificacao then
local variavelDoArquivo = 123
end
-- preciso acessar a variável que foi criada pelo if verificação fora do if mas no mesmo arquivo. Ex:
print(variavelDoArquivo)
Behold functioning on the ideone and in Codingground.
In this situation returned blank on the console, but in some cases returned nil in other situations. How can I create/set a variable within the if
and be able to access it externally without having to create a scope?
I don’t know if you’re doing what you want, but it’s the solution. I think initialize the variable already in the statement and only change its value within the if
would be better, but it depends on the outcome you expect.