Wait
Displaying 1-8 of 8 total.
1
Please enter a numerical value for the importance of this sticky.
Enter 0 to unsticky.
miky

How would you do a wait function (that waits to continue until the time specification is over)?

The one in the manual doesn't exist.

Posted on 2006-10-26 20:26:30

choris

I'll beat Interference22 to it. As he often says...

Posted on 2006-10-27 01:41:46

miky

Actually, I was looking more for a function that paused the current function. And I've already found one (and it's a lot shorter than yours). Here it is:
void wait(int delay)
{
t = timer;
timer = 0;
while(delay)
{
while(timer)
{
timer--;
delay--;
UpdateControls();
}
}
timer = t;
}

Posted on 2006-11-01 17:37:12 (last edited on 2006-11-01 17:39:27)

Overkill

Quote:Originally posted by miky

Actually, I was looking more for a function that paused the current function. And I've already found one (and it's a lot shorter than yours). Here it is:
void wait(int delay)
{
t = timer;
timer = 0;
while(delay)
{
while(timer)
{
timer--;
delay--;
UpdateControls();
}
}
timer = t;
}


I would argue that is a very inefficient way to wait a specified amount of time. People with slow computers will likely end up waiting far longer than the desired interval, and fast computers might end up finishing faster than expected.

Use this instead.

// Halts execution for the specified interval, in centiseconds.
void Wait(int delay)
{
int timestamp = systemtime;
while (systemtime - timestamp < delay)
{
UpdateControls();
}
}


It should be noted, it's very similar to how Interference goes about his Wait() function. It just uses systemtime instead of timer. I don't use timer, ever, because I never have a need to modify the timer, because timestamps are way more efficient than manually altering builtin timer variables.

Also, depending on what you're doing, using wait functions aren't a very efficient way to approach things. If you're just trying to slow down something because it's moving too fast, you might consider what I call frame throttling.

Posted on 2006-11-03 14:21:48 (last edited on 2006-11-03 14:29:08)

Gayo

I would recommend using timer instead of systemtime. If you use systemtime it may cause problems with the fast-forward option, and there's always the possibility of something going catastrophically wrong (or allowing some sort of sneaky cheat) if people alter their system time while the game is running.

Posted on 2006-11-03 20:46:25

Overkill

Quote:Originally posted by Gayo

I would recommend using timer instead of systemtime. If you use systemtime it may cause problems with the fast-forward option, and there's always the possibility of something going catastrophically wrong (or allowing some sort of sneaky cheat) if people alter their system time while the game is running.


Actually, systemtime is affected by the fast-forward option in the same way as the timer, and systemtime is initialized to 0 when the program begins, and gives the time that has elapsed since the program started. It has nothing to do with the actual system clock.

Posted on 2006-11-04 01:02:03

Kildorf

Quote:Originally posted by Overkill

Actually, systemtime is affected by the fast-forward option in the same way as the timer, and systemtime is initialized to 0 when the program begins, and gives the time that has elapsed since the program started. It has nothing to do with the actual system clock.


Seriously? Because that's not what the docs say. Either you're wrong or the docs should be fixed!

Posted on 2006-11-06 17:40:10

Overkill

The docs are wrong. I'll correct that.

Test code:
void Autoexec()
{ while(!b1)
{
RectFill(0, 0, ImageWidth(screen), ImageHeight(screen), 0, screen);
PrintString(2, 2, screen, 0, str(systemtime));
Log(str(systemtime));
Showpage();
}
}
Results from v3.log (trimmed to be less annoying):

6
8
9
9
10
11
12
13
14
14
15
16
17
18
19
19
20
21
22
23
23
24
25
26
27
27
28
29
30
31
32
33
33
34
35
36
37
37
38
39
40
41
42
43
44
45
46
47
48
48
49
50
51
52
53
54
54
55
56
57
58
59
59
61
61
62
63
64
65
66
66
67
68
69
70

Posted on 2006-11-09 14:03:22 (last edited on 2006-11-09 14:06:05)


Displaying 1-8 of 8 total.
1
 
Newest messages

Ben McGraw's lovingly crafted this website from scratch for years.
It's a lot prettier this go around because of Jon Wofford.
Verge-rpg.com is a member of the lunarnet irc network, and would like to take this opportunity to remind you that regardless how babies taste, it is wrong to eat them.