SRL Archive - SRL Archives

A little wait function


Rich

2011-10-28 12:36:29

Nothing special; I just got fed up of writing + Random(x) and I'm sure many others do.

{*******************************************************************************
procedure RWait(Time, RTime : Integer; Minus : Boolean);
by: Rich
Description: Waits Time + random RTime. Maybe - random RTime if Minus set True
*******************************************************************************}
procedure RWait(Time, RTime : Integer; Minus : Boolean);
begin
Wait(Time + RandomRange(- (Integer(Minus) * RTime), RTime));
end;

I'll be honest I've not got my hopes up for this, but I thought I might as well post it.

Sir R. M8gic1an

2011-10-28 12:42:48

Whats the point of minus?

RWait(500, 75, 25, true)
is exactly the same as
RWait(500, 50, 0, false)
every single time…

-RM

Rich

2011-10-28 13:41:55

From: Sir R. M8gic1an
Whats the point of minus?

RWait(500, 75, 25, true)
is exactly the same as
RWait(500, 50, 0, false)
every single time…

-RM
Not sure where that fourth parameter has come from.
Having minus set as true gives the effect of
+ RandomRange(-RTime, RTime)
whereas having it false does
+ Random(RTime)

EDIT:
program Test;
var
I : Integer;

function RWait(Time, RTime : Integer; Minus : Boolean) : Integer;
begin
Result:=(Time + RandomRange(- (Integer(Minus) * RTime), RTime));
end;

begin
WriteLn('Minus FALSE');
for I:= 0 to 9 do
WriteLn(RWait(5000, 2500, False));
WriteLn('');
WriteLn('');
WriteLn('');
WriteLn('Minus TRUE');
for I:= 0 to 9 do
WriteLn(RWait(5000, 2500, True));
end.
Run that and you get:
Minus FALSE
7360
6214
7470
5257
7150
6051
7484
7185
5645
7056



Minus TRUE
2929
6307
6847
5708
3452
7048
7112
3442
4365
4090
Where the numbers would be the time waited. Notice with Minus as True that it has the chance to minus random RTime instead of just adding it on.

Sir R. M8gic1an

2011-10-28 13:49:52

true, true, had misinterpreted it, sorry about that :)

-RM

Rich

2011-10-28 13:54:39

No problem :)

Jakkle

2011-10-28 23:17:58

From: Rich
Nothing special; I just got fed up of writing + Random(x) and I'm sure many others do.


Me to, it ain't a big deal but will help out a lot as waits are a quite a big part of scripting. Less to right the better :p (I know I'm lazy lol).

Nice job :)

Coh3n

2011-11-26 02:43:46

Ehh I don't really think it has a place in SRL. People can just add it to their script if needed. I'm sure it's handy, though. :)