locals disappear

Hi, i need some help ! Please see the following code

1
2
3
4
5
6
7
8
9
10
11
12
useRetina = true
 
if useRetina then
        local formNeuText = ""
        local btOffset = -5
        print ("btOffset: " .. btOffset)
else
        local formNeuText = languageTable[def_new2]
        local btOffset = 5
end
        
print ("btOffset: " .. btOffset)

Your btOffset is out of scope by the time you reach your second print statement. It's scope is local to that first if statement block.

Change your code to this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
useRetina = true
 
local btOffset = 0
 
if useRetina then
        local formNeuText = ""
        btOffset = -5
        print ("btOffset: " .. btOffset)
else
        local formNeuText = languageTable[def_new2]
        btOffset = 5
end
        
print ("btOffset: " .. btOffset)

thanks :-)

No problem!

views:1340 update:2011/9/29 19:21:19
corona forums © 2003-2011