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'm working on a Lua file similar to this schema:
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)
See working on ideone and on 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 if
and be able to access it externally without having to create a scope?
I do not know if you're doing what you want, but it's the solution. I think initializing the variable already in the statement and just changing its value inside the if
would be better, but it depends on the result you expect.