Hi,
I am having problems with a specific value that is passed to the screen from the calling screen. The value comes through fine initially, then disappears for no apparent reason, resulting in “error”. please help.
This code was working fine before and I am having issues because I have made changes introducing “levels” and passing appropriate values based on the level chosen by the user.
I have tried 3 options, 1. using persistent storyboard variables 2. passing params between screens and 3. even setting up a local variable a1=1.
The value gets passed on properly but somehow the values for a1 disappears by the time I define my button and try to set the text value, based on a data array. I checked memory usage and it is about .5 MB. Is there a limitation as to how many variables can be active in memory in corona?
-thanks
==================================
function scene:createScene( event )
local screenGroup = self.view
local params = event.params
coinscnt = storyboard.state.coins
seqno = storyboard.state.seqno
a2 = params.p_seqno --a2 gets value 1 properly here
print( "inside main scene " … collectgarbage(“count”)/1000 … “MB”)
if storyboard.state.level == 1 then
wordsData = table.copy( wordsData1)
--print("w1: ", wordsData[seqno].w1)
end
if storyboard.state.level == 2 then
wordsData = table.copy( wordsData2)
end
local y = 1
while (y < 11) do
print("wordsdata: ", wordsData[y].name, wordsData[y].w1 ) --data array has proper values
y = (y+1)
end
print("1 a2 val: ", a2) --a2 value good until here
background = display.newImageRect( “bgblue3.png”, 640, 960 )
background.x = display.contentCenterX;
background.y = display.contentCenterY;
screenGroup:insert( background )
backb = display.newImageRect( “back1.png”, 30, 30 )
backb.x = 30;
backb.y = 20;
puzzno = display.newText(a1, 80 , 20, “verdana”, 16)
puzzno.x = 80
puzzno.y = 20
puzzno:setTextColor(74, 74, 74)
moreb = display.newImageRect( “more1.png”, 30, 30 )
moreb.x = 280;
moreb.y = 20;
imgcoins = display.newImageRect( “coins.png”, 30, 30 )
imgcoins.x = centerX - 20;
imgcoins.y = 20;
coinsText = display.newText(coinscnt, centerX+20 , 8, “verdana”, 16)
coinsText:setTextColor(74, 74, 74)
screenGroup:insert( backb )
screenGroup:insert( puzzno )
screenGroup:insert( moreb )
screenGroup:insert( imgcoins )
screenGroup:insert( coinsText )
myButton1 = widget.newButton
{
left = qn1Xpos,
top = qn1Ypos,
width = ansbutwidth,
height = ansbutht,
label = “Default”,
labelAlign = “center”,
font = “Verdana”,
fontSize = 18,
textonly = true,
labelColor = { default = {40,40,40}, over = {255,255,255} },
onEvent = onButtonEvent
}
myButton1.baseLabel = “Default”
myButton1.setReferencePoint = (display.CenterReferencePoint)
print("a2 before setting mybutt: ", a2, wordsData[1].w1) --a2 value is nil causing error in the next line
–myButton1:setLabel( wordsData[a2].w1 ) – this works. array has proper values
myButton1:setLabel( wordsData[a2].w1 ) --error due to a2 being nil
debug results:
mem usage: 0.574724609375MB
2013-08-31 19:15:36.314 Corona Simulator[212:707] wordsdata: Lion King Characters Simba
2013-08-31 19:15:36.315 Corona Simulator[212:707] 1 a2 val: 1
2013-08-31 19:15:36.334 Corona Simulator[212:707] a2 before setting mybutt: Dalmatian
2013-08-31 19:15:36.340 Corona Simulator[212:707] Runtime error
/Applications/fourwords1Group/scrMain.lua:365: attempt to index field ‘?’ (a nil value)
stack traceback:
==============================================================