monster:rotate(1) error

I have got so far in to my current project and only had a few errors and I came across a new one today. I get the error:
Runtime error
document path//game.lua:333 attempt to call method “rotate”
stack traceback
[c]: in function “rotate”
document path//game.lua:333 in function “updatemonster”
I have looked at the line that it says there is a problem and I cannot see any problem.
here is the code block that contains the error. I have highlighted the line 333 for you.

function updateMonster()  
 --if our monster is jumping then switch to the jumping animation  
 --if not keep playing the running animation  
 if(monster.isAlive == true) then  
 if(onGround) then  
 if(wasOnGround) then  
   
 else  
 monster:prepare("running")  
 monster:play()  
 end  
 else  
 monster:prepare("jumping")  
 monster:play()  
 end  
 if(monster.accel \> 0) then  
 monster.accel = monster.accel - 1  
 end  
 monster.y = monster.y - monster.accel  
 monster.y = monster.y - monster.gravity  
 else  
----------------\>line of code with error----------------\>  
 monster:rotate(1)  
 end  
 --update the collisionRect to stay in front of the monster  
 collisionRect.y = monster.y  
end  

If someone could help me as I am so close to finishing.

Thanks

Ryan [import]uid: 111430 topic_id: 26728 reply_id: 326728[/import]

Forgot to mention that when the game ends a pop up appears and asks the used to tap to continue and doing so takes you to the gameover screen “gameover.lua” (i am using director) I get the error after the user has tapped the button and has gone on to the other screen.
Thanks
Ryan [import]uid: 111430 topic_id: 26728 reply_id: 108342[/import]

I would add a print statement to verify your “monster” object is valid.

print( "Monster: " .. tostring(monster) )

If “monster” prints out as nil, there will be no rotate method to call. [import]uid: 7559 topic_id: 26728 reply_id: 108382[/import]

Hi Tom Thanks for your reply i have added your line of code to my project and i get the following back in he debugger.

monster: table 09958030

and I still get the same error.

The code I have used works in a different project but on this one i does not.

Is there something else I can try?

Thanks
Ryan [import]uid: 111430 topic_id: 26728 reply_id: 108459[/import]

I have been trying everything including removing the line of code and anything to do with it but it just keeps bringing up more errors.

Someone have a solution. I don’t need the monster to rotate but I do like the effect. If there is nothing i can do to stop the error mentioned above I can delete the line and post up the other error I get and the line of code that I get.
Would love some help

Thanks
Ryan [import]uid: 111430 topic_id: 26728 reply_id: 108689[/import]

Are you sure it’s a Display Object? Try printing out monster.x and monster.y and see if you get numbers or nil. Maybe this object has already been removed because of the screen transition.

Update: You can also test to see if there is a “rotate” function associated with the object with this code:

print( "monster rotate: " .. tostring( monster.rotate ) )

It should display “function” and the address. [import]uid: 7559 topic_id: 26728 reply_id: 108706[/import]

I used the code you published last time and got numbers and i spoke to a friend who has also had this problem before and he said to delete all of the code related to the rotation and it should work but that did not.

What line of code and which file should i use you code in. I have tried getting the monster to appear in the gameover file and it just through up more errors.

What can i try. I really need to get this sorted I don’t have long to get this project done and then start work on the others for launch later this year.

Thanks
Ryan [import]uid: 111430 topic_id: 26728 reply_id: 108710[/import]

You should add the test code right before the line where you are getting the runtime error. My bet is the object has been removed, which leaves a plain table without any of the display object properties or methods.

Director Class will remove object after screen transitions so there may be a timing problem in trying to use an object that Director has removed. [import]uid: 7559 topic_id: 26728 reply_id: 108711[/import]

Hi Tom I have just tried that line in the postion you said and i got back the following line;

monster rotate: function: 099E0B30 (this line repeats itself until i click the next button, also each line is a different number)
monster rotate: nil

and then I get the same error saying that it is

I am not sure what i have done wrong or what is wrong.

Thanks

Ryan [import]uid: 111430 topic_id: 26728 reply_id: 108713[/import]

If you get “monster rotate: nil” right before the runtime error, it’s because the object has been removed (most likely with a “monster:removeSelf()” statement so you are calling a method (“rotate”) on an object that no longer is valid. I suspect Director is removing your object because you inserted it into the display group for that screen.

This is not a problem with Corona but an issue with Director Class or more likely, you program code flow. [import]uid: 7559 topic_id: 26728 reply_id: 108715[/import]

Hi Tom
I based my project on a template i found jut to get an idea of what to do and the demo works fine with this line of code and director and it works fine. I am just gonna mess around with the code this evening and see what I can do [import]uid: 111430 topic_id: 26728 reply_id: 108721[/import]

Hi tom
I have read that other people have the same sort of problems with director and build 2011.704 and they suggest going over to storyboard. IO shall try this out. hopefully this will solve my problems.

Thanks for your help
I will post here if this has worked.

Thanks
Ryan [import]uid: 111430 topic_id: 26728 reply_id: 108732[/import]