Would need to see the specific error your getting. There is nothing wrong with the code you posted. If setting rotation errors, the likely issue is spaceship is nil, therefore rotation does not exist.
Since your not getting errors before the rotation I will have to assume spaceship is not nil. It could be scope issue. If you remove local from spaceship to in turn make it global, does the error go away?
I tried out the print statements, and the console prints it out just fine: spaceship, spaceship.rotation. The function is definitely being executed. Only up until the end, the simulator calls a Runtime error and halts the program, and the same error as before appears.
The console should print something like “table: 0x10d364110” for the spaceship and a number for the rotation. Is it printing that? Or is it printing what you posted - “spaceship”, “spaceship.rotation”?
Sorry, I didn’t put the whole output from the console: table: 0x10ac33500 12105.015625. So is this just a value for the function?
I did a command search for “spaceship.rotation =”. The only two occurrences of it are in the code I posted above, so it is not being changed into anything I don’t want.
I apologize for not understanding, but how will this help solve the error I’m getting?
I had already tried removing the spaceship.rotation = spaceship.rotation, but it didn’t make a difference. I changed the print statement to just spaceship.rotation in the function, and this time only the numbers were popping up; no ‘table’. It was incrementing by 45 each time. The output is:
Looking at your last reply it appears the spaceship is rotating. So when exactly does this error happen? If you do nothing does it happen randomly or do you have physics collisions happening. There is obviously more to it than just a spaceship rotating. Something in the code is causing spaceship to nil out.
Do you have a collision function that removes the spaceship if it hits something or something hits it? If you remove the spaceship, you need to kill the timer or it will attempt to rotate the spaceship that no longer exists.
Once a display object is converted to a physics object, you cannot directly rotate the object using object.rotation or object:rotate(). The object will rotate but the physics part of the object won’t rotate. You can see this by turning on physics.setDrawMode().
Wow. You’re absolutely right! I forgot to remove the timer in my collision function, and it was trying to rotate a nil spaceship. After I put in timer.cancel(satmr), the error went away.
Sorry, I’m only 15 years old, so I am not very experienced in programming yet, and it’s always the little errors that get me. Thank you everyone for all your help!
Would need to see the specific error your getting. There is nothing wrong with the code you posted. If setting rotation errors, the likely issue is spaceship is nil, therefore rotation does not exist.
Since your not getting errors before the rotation I will have to assume spaceship is not nil. It could be scope issue. If you remove local from spaceship to in turn make it global, does the error go away?