Director question

I have a button to go back to a previous scene, and I cannot get it to work. The button appears if one of a series of elseif conditions are met.
local backButton = display.newImage (“playButton.jpg”)
backButton.x = 160
backButton.y = 440
localGroup:insert(backButton)
But when I load the level I get this error: “attempt to index global ‘backButton’ (a nil value)”

I’ve tried the function and the button and the listener in a separate file, so I know those parts are correct.

Is this enough of a clue to get me looking in the right direction for a solution? I’d sure appreciate any help. [import]uid: 96383 topic_id: 16652 reply_id: 316652[/import]

You might want to forward reference backButton before it is first used in the module:

EDIT:
[lua]local backButton
.
.
–somewhere between local backButton and the actual definition of backButton,
–you may find backButton included in a line of code.
.
.
– later on, where you have it, define backButton like:
backButton = display.newImage (“playButton.jpg”)
backButton.x = 160
backButton.y = 440
localGroup:insert(backButton)[/lua]

If it doesn’t do it, I have no clue why you’ve got the error. [import]uid: 67217 topic_id: 16652 reply_id: 62197[/import]

Thanks, I thought it might be that, but I ran a find/replace and the only places backButton appears are the places it is supposed to appear. Maybe someone else has a thought?

[import]uid: 96383 topic_id: 16652 reply_id: 62204[/import]

I had a similar thing happen, where I inadvertently deleted a line that defined the localGroup:

[lua]local localGroup = display.newGroup()[/lua]

Can it be, the localGroup is named differently for the module, but you are trying to insert the button to “localGroup” that doesn’t exist?

If not, you probably need to post the code block that causes problem so that someone knowledgeable can help debug. [import]uid: 67217 topic_id: 16652 reply_id: 62211[/import]

Hey Naomi, it seems to me (and I am a rank beginner, so I could be wrong!) that all the localGroup related syntax is in place. In fact, when I comment out the other 3 listeners (2 runtime, one other touch) the button works the way it is supposed to. [import]uid: 96383 topic_id: 16652 reply_id: 62223[/import]

Also, since I don’t know where the problem lies, I’d have to post about 300 lines of code. Seems kind of excessive to ask anybody to slog through that… ? The generosity of this forum must know SOME bounds! Although I have yet to come across them, it’s an unbelievably helpful bunch of folks. I just don’t want to seem ridiculous. [import]uid: 96383 topic_id: 16652 reply_id: 62225[/import]

You may want to narrow down the problem then.

You mentioned there are 3 listeners, and if you comment them out, the issue goes away. That means, you’ve got a problem with one or more of these 3 listeners. Careful look at each of the listeners might just let you solve the problem. [import]uid: 67217 topic_id: 16652 reply_id: 62226[/import]

LOL. It’s all of them. Comment out all three, and I can get the button to work. Uncomment any one of them, and I start getting errors. [import]uid: 96383 topic_id: 16652 reply_id: 62227[/import]