toFront() a nil value

Hey guys.

I am having an issue with object:toFront()

It works fine the first time then upon trying to call it again i get : “Attempt to call method ‘toFront’ a nil value”

I reset the object with object:toBack() before calling object:toFront() again but i cannot seem to bypass the error.

Help is greatly appreciated. [import]uid: 6981 topic_id: 10077 reply_id: 310077[/import]

bump [import]uid: 6981 topic_id: 10077 reply_id: 36940[/import]

As usual fixed it before even getting a response.

Shame…

[import]uid: 6981 topic_id: 10077 reply_id: 37064[/import]

Hey,

Well done on fixing it - was it in fact a bug?

Peach :slight_smile: [import]uid: 52491 topic_id: 10077 reply_id: 37095[/import]

I think it is but i found a work around so its all good [import]uid: 6981 topic_id: 10077 reply_id: 37149[/import]

What did you do to fix it? [import]uid: 24111 topic_id: 10077 reply_id: 45698[/import]

@infuseddreams,

Any chance you go elaborate on how you worked around this issue, or anyone with a clue as to how to fix this error?

I am getting the same error and I’m pulling my hair out here trying to figure it out.

Thanks,

-Clark

[import]uid: 5786 topic_id: 10077 reply_id: 84555[/import]

Usually when you get an object function that is nil, its because you’ve written over the object variable… something similar to:

local apple = 1

apple = display.newImage(“apple.png”)
apple:toFront() – works

apple = apple + 1 – just lost your apple object

apple:toFront() – toFront() is now nil.

or the other case:

apple = display.newImage(“apple.png”)
apple:toFront() – works

apple:removeSelf()

apple:toFront() – is nil.

I don’t know if that’s your case or not, but when I’ve found a function missing that should be there its because I screwed up and had trashed the object earlier.
[import]uid: 19626 topic_id: 10077 reply_id: 84564[/import]

Thanks Rob,

Yea my case is a little weird and kind of confusing to explain but basically all I am trying to do is pause my game when the application is suspended so when you return to the game it shows the pause menu instead of just throwing you instantly back into game-play.

I have a pause function I set up and have used that on application suspend. This is a type of trivia game that I am using the director class to load a new scene and display the next question.

The application suspend works just fine when I run it on the first question, but after that when running it I get the nil value described above.

I tried to do it another way by just creating new objects on suspend so they would be on front automatically but that created even more very strange issues.

Don’t know if that is at all understandable or not, I think I may be misunderstanding how the application suspend and resume are suppose to work.

[import]uid: 5786 topic_id: 10077 reply_id: 84566[/import]

I ran into this before because a listener was removing the instance of an object without me knowing it, so it ended up being user-error on my part.

You might re-trace the footsteps of the life of that object instance in your code to make sure it has not been removed when you go to call toFront. [import]uid: 52430 topic_id: 10077 reply_id: 84570[/import]

Oh yea I have no doubt it is an error on my part (Just realized this post was originally created under the bugs section which doesn’t really apply to my issue, my apologies it was just the only thread I saw about it.)

What is strange and I am having a hard to understanding is I am using the director class to basically reload the same file to display the next question. So the code is basically exactly the same so I can’t get why it would work on the first question and then stop working after that.

[import]uid: 5786 topic_id: 10077 reply_id: 84578[/import]