please help… when i try to restart it show up error "level1.lua:137: attempt to call method ‘applyForce’ (a nil value) stack traceback: but when from menu to game… its ok no problem… just onlyu when i try to restart… please help… dont know how to fix it now dis is my level1.lua (game.lua) n my remenu.lua (restart.lua)
Hello,
The community/staff can’t help you very much because we don’t have any context to what your code is doing. We don’t know what you’ve written, what line 137 is, etc.
That being said, you’re getting an error that indicates a scope issue. If you’re new to Corona/Lua, you really must explore and fully learn about scope before proceeding too far. It’s one of the most fundamental aspects of programming in Lua, and if you don’t understand it now, please take time to learn about it. This tutorial should get you started:
https://coronalabs.com/blog/2015/06/16/tutorial-scope-for-beginners/
And this video:
Hi @charlesleo1993,
Can you please edit your post, surround the code with “lua” tags for clarity in the forums, and also add proper indentation of code lines/blocks? The staff/community can help you much better if your code is readable.
[lua] -- code [/lua]
Thanks,
Brent
Hi @charlesleo1993,
I believe the problem is that you’re adding the “onScreenTouch” event listener to the Runtime. Since the Runtime is “global” it exists in both scenes, but the “pony” only exists in the “game.lua” scene. So, when you touch the screen and the pony does not exist, Corona attempts to find the “pony” object and apply physical force to it, but since the pony does not exist in both scenes, it can crash.
I suggest that you be careful which things you add as Runtime event listeners. A screen touch is generally better served by adding a “touch” event listener to the display stage (display.currentStage or display.getCurrentStage()), or to a invisible but touch-sensitive vector rectangle which covers the entire screen. If you do so, remember to add the “touch” listener after the scene shows (scene:show() with phase of “did”), and then remove the touch listener when the scene is about to hide (scene:hide() with phase of “will”). That way, you won’t get inadvertent touches going through to phases of the scene (or to the other scene) where the pony doesn’t exist.
Hope this helps,
Brent
hi brent… can u just fix it for me… iam really need a help…
Hello,
The community/staff can’t help you very much because we don’t have any context to what your code is doing. We don’t know what you’ve written, what line 137 is, etc.
That being said, you’re getting an error that indicates a scope issue. If you’re new to Corona/Lua, you really must explore and fully learn about scope before proceeding too far. It’s one of the most fundamental aspects of programming in Lua, and if you don’t understand it now, please take time to learn about it. This tutorial should get you started:
https://coronalabs.com/blog/2015/06/16/tutorial-scope-for-beginners/
And this video:
Hi @charlesleo1993,
Can you please edit your post, surround the code with “lua” tags for clarity in the forums, and also add proper indentation of code lines/blocks? The staff/community can help you much better if your code is readable.
[lua] -- code [/lua]
Thanks,
Brent
Hi @charlesleo1993,
I believe the problem is that you’re adding the “onScreenTouch” event listener to the Runtime. Since the Runtime is “global” it exists in both scenes, but the “pony” only exists in the “game.lua” scene. So, when you touch the screen and the pony does not exist, Corona attempts to find the “pony” object and apply physical force to it, but since the pony does not exist in both scenes, it can crash.
I suggest that you be careful which things you add as Runtime event listeners. A screen touch is generally better served by adding a “touch” event listener to the display stage (display.currentStage or display.getCurrentStage()), or to a invisible but touch-sensitive vector rectangle which covers the entire screen. If you do so, remember to add the “touch” listener after the scene shows (scene:show() with phase of “did”), and then remove the touch listener when the scene is about to hide (scene:hide() with phase of “will”). That way, you won’t get inadvertent touches going through to phases of the scene (or to the other scene) where the pony doesn’t exist.
Hope this helps,
Brent
hi brent… can u just fix it for me… iam really need a help…