reset a game

is there an easy way to reset a game? right now i have a periodic function that flashes you lose after 10secs. can i make this reset my game too?

heres the code i have.

def myPeriodicFunc(task):
print ‘10 seconds have elapsed’
return task.again

    taskMgr.doMethodLater(10, myPeriodicFunc, 'myPeriodicFunc')

the setScale is because my text scale is 0 to start, and then it makes it visible after 10 seconds.


Sure, but be careful how you use the taskMgr. The code you have will perpetually call “myPeriodicFunc()” every 10 seconds until you remove the task from the taskMgr. Returning “task.again” tells the taskMgr call the function again after the specified amount of time. If you just want it to be called only once after 10 seconds, you could do something like this:

def myDelayedFunc():
   print '10 seconds have elapsed'

taskMgr.doMethodLater(10, myDelayedFunc, 'myDelayedFunc',[]) 

Notice three things:
-the lack of the “task” parameter to our function
-the absence of the “task.again” in the return statement
-the extra “[]” argument to the doMethodLater() call.

This is the simplest way to use the doMethodLater() function. So if you were to write a function that reset your game, you could indeed call it inside meDelayedFunc().

thanks for the reply! you’re giving me too much credit though lol. my really question ws actually, how do i reset my game? im a complete noob and i cant find anything to even start making a function that will reset my game lol.

Panda doesn’t really provide a “resetGame()” function, since it has no idea what it means for your game to be reset. It could be as simple as resetting a score, moving ralph back to his starting position, and resetting his health or something. It all depends on the needs of your game.

Once you’ve defined that, you could wrap it all up in a function call, and you should be good to go. Good luck!

thanks! ill try… something!

Finite state machines (FSM’s) can make that kind of stuff easier.