Is there a way to do a clean 'restart game' via API?

I'm working on the 'New Game' option item for my game. During normal development, I'd just exit the simulator, go to my Disk/Data/mygame directory and delete everything, then restart the simulator - clean game state!

So now I'm implementing 'New Game', which first thing goes and deletes everything in Disk/Data/mygame, but... I've still got tons of tables/variables/etc. that still have contents that I don't want/need... and there's lots of them (and a pain to track down/reset them one by one - there's lots).

This would be simpler if there were a SDK function to just 'restart my game' that I could call after wiping all that old datastore... then everything would just come up clean again as if the game had never been played.

Is that possible? I've looked through the SDK docs and searched here in the forum and haven't seen anything.

could you run your main file again?

https://sdk.play.date/inside-playdate/#f-file.run

"could you run your main file again?"

I don't know... does that nest? (sort of, you know, stack-ishly?)

And (if it's ok to do that) could you be a little more specific as to exactly what I'd pass as an argument? It's probably obvious to the Devs but I haven't a clue.

Aside: less of an issue now, I went back and tracked down the errant statevar that was giving me problems - but there's also been recent forum traffic about invoking separate chunks of a game that's relevant in intent with this thread, so still might be useful to explore things further.

Thanks!

No, only one thing will run at a time. It'll be like restarting your app.

You'd pass main.pdz unless you have one called something different. Take a look inside your .pdx

1 Like

I'll give it a shot.

Thanks!

I would say that memory isn't cleared when you do this, so be wary of bugs if you have initializer code designed to run only once.

If not points then 
  points = 0
end 

In this example, points won't be reset to 0 if you run main.pdz a second time

Interesting! So global space is not cleared?

To work around that you could use env with a table you clear before running. You could also run the pdz early in your logic so that it always uses this instead of global _G.

Have to admit I did not test the above, but I'd say _G persists when using file.run. You can try, of course :slight_smile: