Level restart / Code Finish

Sorry for naive beginner questions, but...

I am building a simple game that has multiple levels of difficulty. I setup initial stage, add display elements, run listeners ...etc., BUT what do I need to do to restart when I need to switch to a higher level of complexity? That is, levels only differ by some constants (such as speed) but are essentially the same, so do I need to unload all of the display elements, remove all listeners and then redo everything from scratch? ... and if so, is there a "goto" command in LUA? Along the same lines, how does one finish or end code? How do I "exit" from the game when the user hits 'quit'?

Sorry for a barrage of questions, but they are all related. Thanks in advance !!

Oleg

what do you mean by exit the game? when player exits the game and starts it again(not suspend app, but exit) code will start all over
if you dont want this to happen you need to save and load your data

for different difficulties you probably want to create a table or variables that will contain various values for your game logic and upon doing something you will change that values and so the game will be easier or otherwise

hope it makes sense)

Thanks for the reply.

Just to clarify, when the player presses "exit" or "quit" what would be the command to effectively end the code and exit?

For levels, I did implement the values tables, but when I remove the existing scene and recreate it (with new values) do I also need to remove listeners and such? Is there is a "standard" way of doing this?

Thanks again,

Oleg

This line of code will exit the app and kill the process.

1
 os.exit

@olegat,

Many developer here do not read the Apple guidelines for their apps, and do become a bit stubborn to a suggestion. I can tell you this..

If you quit an app, i.e. tha app drops back to the Home Screen, it is in Apple's terms equivalent of a Crash. The only way an app should go to the Home Screen is via the Home Button.

So, please let's not have a discussion on this, I am just letting you and the other know what Apples policies are. You could be lucky that the reviewer that reviews your app might not look for this and let it slip, but then if it does not, you will face unnecessary delays and change in code.

cheers,

?:)

Thanks all for responses and the "heads-up" on the quit process.

Can you explain

"director:changeScene("level1",crossfade)"

- what does it mean, what is 'director' (I assume some external class) and can similar be done in native Lua without calling external classes?

Thank you,

Oleg

@jayant Glad to know that about apple. Though I am only developing for android now. I hope to develop apps for apple in the future. Good stuff to know.

@oleglat

Yes director is an external class for switching diffrent scenes. Just do some searches for it on the forum and you will know all about it.

If you do not need to switch screens then I would make a function to set all your variables to the what they were when you started the level. Also set all your display images to where they were when you started the level then call that function when you want to reset the level.

Do some searches on the forums there are many questions that you have that have been answered.

I too had the same question as you, that was about 2 months ago I did searches found suggestions and went form there.

(you can learn from copying and pasting someone elses code but only to an extent, to fully understand whats going on you need to take that code you copied and play with it.) Mess it up even, then debug it.

Be the code, Love the code, Hate the code, Live the code. Lol

I would start small if you need to learn how to reset your level just make a sort of template of what you are trying to accomplish

Just make a new project and work on a small example of what you are trying to implement. get it working and apply it to your game.

goodLuck.

views:1316 update:2011/10/16 9:47:44
corona forums © 2003-2011