Author Topic: waiting in script/special functions  (Read 2852 times)

ragingmime

  • Visitor
  • *
  • Posts: 11
    • View Profile
waiting in script/special functions
« on: 2006-03-04, 09:44:28 PM »
I'm setting up a special function that, when a player collides with an enemy, will replace the player with a "hurt" sprite (which won't collide with enemies), wait for a few seconds, and then switch back to the player sprite. Is there any way to implement this waiting period in special functions or script? (I mean, I guess I could just put a for loop or a counting function that executes every frame in the script, but there's got to be a more elegant solution than that.

[edit]: I've been poking around in the code reference, and I came across the OnFrameStart event. I've got the framerate capped, so I guess I could increment a variable every frame, and when the player gets hit I could store the current frame number. Once the difference between the current and stored frame number reaches X, I could switch back. But that's (relatively) slow and inelegant. (Plus, having a variable that constantly increases forever would probably crash the game if it were left on long enough, so that's probably not a good idea). Am I missing something that's right in my face, or should I go ahead and start coding what I've described?

Thanks in advance.
« Last Edit: 2006-03-04, 10:28:50 PM by ragingmime »

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2761
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
Re: waiting in script/special functions
« Reply #1 on: 2006-03-05, 07:38:30 AM »
There are many different ways to do this, both scripted and unscripted.  I don't think you would run into problems by incrementing a script variable every frame because you wouldn't hit an error about the number getting too big until at least 2 billion frames have passed, and at 60 frames per second, that would take more than a year.  But if you were concerned about it, you could also set the variable to some number and decrease it until it hits zero and then stop.

For a full answer/solution to your problem I suggest an article I recently saw posted on Guildhall's forums.  Someone developed a class to help queue timed events: http://guildhall.proboards15.com/index.cgi?board=Level&action=display&thread=1140822089.  It's a little over-designed, IMO, but that doesn't matter if all you have to do is use it and not understand how it works.