Delay? WaitTimer? WaitEvent? Delta timing?

BlitzPlus Forums/BlitzPlus Programming/Delay? WaitTimer? WaitEvent? Delta timing?

Tomas Khan(Posted 2008) [#1]
I learned my programming from the book Game Programming for Teens, by Maneesh Sethi. As a result, I tend to do things sort of the way he does things, and so I use the Delay function to keep my games from running at supersonic speeds. However, then, looking around this forum, I've heard things that sound like "WaitTimer is better for having it run the same on every computer!" "No, delta timing works better than timers!"

In short, I'm puzzled.

Delay has always worked fine for me; I've only used it on one computer, but when it's slowed down it's done it abruptly when a bunch of enemies show up. However, spurred on by rumors of WaitTimer being better, I decided to try it. When I tried running the program with
frametimer = CreateTimer([insert number here])
...
WaitTimer(frametimer)

all it says is "Function 'waittimer' not found."

Question #1: How do you use 'secret' functions like WaitTimer? Or do you just not?

Next I tried using WaitEvent in place of WaitTimer. Well, that worked... sort of... but whenever my player tried something different (moving from a standing start, jumping, whatever) the whole thing drastically slowed down.

Question #2: Why did it slow down so drastically? It's never done that with a simple Delay.

And then I heard about this delta timing. I'm no expert, of course, and when I tried the link I found in a forum post to a tutorial on delta timing, I found it to be a link to the now-defunct Blitzcoder forums. No help there.

Question #3: What is delta timing?

Summary question: So, what are the differences between Delay, WaitTimer, WaitEvent, and delta timing, and when is each one better than the next?


Sorry about that long-winded explanation, but I wanted to be sure the problem was as clear as I thought it could be. Thank you for your time, and please respond if you can explain it to me.


Sauer(Posted 2008) [#2]
I had this problem a bit ago...

Ok, the basic difference between DELAY and WAITTIMER is that delay slows down your program based on time, whereas WAITTIMER slows down your program depending on frames per second.

If you can use DELAY, that's fine, but you may find sometimes that using DELAY can produce undesired slowdowns in some processes (I can't explain it very well but you'll know when you experience it)

The reason you can't use WAITTIMER is because you need to update your version of blitz. You can do this under the account tab on the Blitz Basic site, then going to product upgrades.

As for delta timing, it regulates your program using time, but does it in such a way that everything is slowed down in proportion. I use delta timing to speed up programs for slower computers, using this bit of code:
;speeding up a game for slower computers

;place this in initialization
Global SpeedFactor#=1.0
Global GameTime=5
Global FrameTime=MilliSecs()

;place this in main loop
SpeedFactor#=Float(MilliSecs()-FrameTime)/Float(GameTime)
FrameTime=MilliSecs()

;multiply every addition equation by SpeedFactor#
x=x+1*SpeedFactor#


As you can see, it takes the frame time and divides it by your desired game time. And that in essence is delta timing.

I hope this helps, good luck.


Tomas Khan(Posted 2008) [#3]
Okay, that was helpful, but still I have a couple questions. First, what was the deal with WaitEvent -- why did it cause such uneven slowing? Second, what do you mean by "every addition equation" in your delta timing example? Third, I'm looking at the "Product updates" page -- you mean "BlitzPlus Update V145," not "BlitzPlus Version 1.11," right, since I have the main thing already? (And it is V145, not V140, isn't it?)

Also, as I said, I have seen a little slowing down when I've been using Delay and a lot of enemies show up all at once, but I don't mind it much because it's so constant, which WaitEvent sure wasn't.

Thank you for your help so far, and please keep on going!


Sauer(Posted 2008) [#4]
Well you want to download the v1.45 first and formost. With the WaitEvent thing, I'm not sure what to tell you, as waitevent is primarily a GUI command.

What I mean by every addition equation is say you have something like "playerx=playerx+10" you could change that to "playerx=playerx+10*Speedfactor" that way it'll do everything proportionally.


Tomas Khan(Posted 2008) [#5]
WaitEvent is listed as a GUI command, but I just thought I'd try it. V145 will make BlitzPlus recognize WaitTimer, you say? And should I just put the downloaded thing in the main BlitzPlus folder?

Also, is what you mean that everything that adds or subtracts a given number from a quantity (score, coordinates, HP and all that) would be multiplied by the speed factor?

Thanks for your help. I'll see about downloading V145 later.


Nate the Great(Posted 2008) [#6]
If you click on the update, (on windows) it should ask you save or run. Click run and it will automatically save it in the right folder.


Tomas Khan(Posted 2008) [#7]
Thanks! I was mixed up for a minute because I clicked on the link, thinking you had meant "Run" would be on there, but I got it.

So, with my v1.45 BlitzPlus, WaitTimer, that "secret" command, is secret no more. And not just that -- it's brilliant! I've put it in that demo I was using where a player character could wander around on the screen while a thousand tiny things fluttered around everywhere (which, because of all those things, slows down considerably with Delay, though not nearly as much as with WaitEvent -- clearly 2D and GUI things shouldn't mix, in that particular way at least), and it looked about the same as when I tried it with WaitTimer and ten little things.

So thank you for your help on Delay, WaitTimer, and WaitEvent. Now the only question I have left on this particular topic is the one I posted before about delta timing:
Also, is what you mean that everything that adds or subtracts a given number from a quantity (score, coordinates, HP and all that) would be multiplied by the speed factor?


Thank you!


Sauer(Posted 2008) [#8]
Uhh no not stuff like that, only stuff you want speeded up for slower computers, like players moving, bullets flying, things being updated. But for those variables that are just showing quantities, you want add those as normal.

I hope that made sense.


Tomas Khan(Posted 2008) [#9]
Well... not really, but I guess I'll just go with WaitTimer, which has only really slowed down once so far and apparently is a whole lot simpler. So instead of attempting to make some sense of delta timing, for now I'll just say "Thank you" and... Wait. Could you direct me to a nice, long example, one that either, say, lists everything that is multiplied by the speed factor, is complete code that properly multiplies all of those things, or goes in-depth with regard to what you do and don't multiply by the speed factor? That might help.

Anyway, thank you!


Sauer(Posted 2008) [#10]
Just don't worry about it... I barely ever use it myself, you'll be totally fine without it.


Tomas Khan(Posted 2008) [#11]
Okay, I guess that's all, then. Thank you!