How to re-run program when it ends?

I made a “Game Over” screen for my game. But I can’t get it to get back to the start of the program with a click. Mind helping? Please tell me the simple way. Thank you very much for your hard work on answering this question.

Could I just tap the screen to restart the program? Without a button?

Whenever I get to a point in my game this happens: error: error: [string “Albi = class()…”]:116: bad argument #1 to ‘stroke’ (number expected, got nil)

Pausing playback

Any help?

You should keep track of the state of your game in a global variable and depending on this state you draw a different scene. In other words:

In your Main file (setup() function):

gameState = "started"

When the game is over:

gameState = "ended"

In your draw function:

if gameState == "started" then
   -- Draw game graphics
elseif gameState == "ended" then
   -- Draw start screen
end

Next to the above, you should draw a ‘button’ with sets gameState to “ended” when hit and re-initializes all your gamesettings.

I hope this gives you the general idea how to manage the state of your game.

May I PM you my main file and you do it for me?

I’ve done everything but I don’t know how to draw a button.

Hehe, I don’t have that much time. But I can point you to an example button: http://twolivesleft.com/Codea/Talk/discussion/1079

After drawing the button on the screen, you should check if the user touches it by checking the touched(touch) function for touch events.

Hi @itsDan - I have just completed a tutorial on adding a button and using it. Have a look at http://codeatuts.blogspot.com.au/

Reefwing it just blacks out my game.

@ItsDan - I’m going to need a bit more to go on…

I suspect you are trying to do too much at once. Try just getting one button to work. I’ve now included Simeon’s RoundRect code in the tutorial. Can you get just a rounded rectangle to draw?

@ItsDan I agree with @Reefwing, it sounds like you are trying to start with something a little bit too complicated. Start a few new projects to try out some simple ideas, then come back to your main one when you have a better understanding of things.

hello @ItsDan. You need to program a state machine to determine what state the game is in and show the correct thing. @Doffer has put you on the right track, I suggest you search around for state machine and learn what that is about. It seems like you are trying to skip some steps.

Hi @Vega I did what @Doffer said I put This in my main setup.

gameState = “started”

When the game is over:

gameState = “ended”

I put this in my Draw setup:

if gameState == “started” then
– Draw game graphics
elseif gameState == “ended” then
– Draw start screen
end

I’m just new to this “Button” thing

And I don’t know how to set the button for the end of the game. I guess I’ll work it out thank you for all your help :slight_smile: