SRL Archive - OSR Help

random choose problem


ogustuce

2012-04-25 15:22:30

i use this in my firemaking script to make it randomly step north or south when get msg (cant light fire here). so here is how it looks like




if FindBlackChatMessage('here') then
begin
case random(1) of
1: begin
WriteLn('Stepping North.');
Mouse(258, 150, 3, 3, True);
While IsMoving do
wait(10);
end;

2: begin
WriteLn('Stepping South.');
Mouse(259, 213, 3, 3, True);
While IsMoving do
wait(10);
end;
end;
end;

the problem is it never steps south(always north) or doesnt move at all

enyone knows why?

Kyle Undefined

2012-04-25 15:24:33

Change the 1/2 of the case to 0/1, because Random(1) returns either 0 or 1.

putonajonny

2012-04-25 15:32:03

From: Kyle Undefined
Change the 1/2 of the case to 0/1, because Random(1) returns either 0 or 1.


Doesn't Random(1) always return 0. He would want Random(2)

Also get rid of those static waits!!!

Kyle Undefined

2012-04-25 15:37:07

It starts at 0, and the number you pass in "1" is the highest it will go. Random(2) will return 0/1/2 ;)

ogustuce

2012-04-25 15:40:04

oh lol ur right how could i forget this (duh)

ogustuce

2012-04-25 15:41:57

:duh:

Abu

2012-04-26 11:12:11

From: Kyle Undefined
Random(2) will return 0/1/2 ;)


Not true. The numbers in the bracket is the number it goes to, starting from 0. So it will return 0 and 1 only.

Proof:
procedure Test;
begin
case Random(2) of

0: Writeln('Got 0');
1: Writeln('Got 1');
2: Writeln('Got 2');

end;
end;

begin
ClearDebug;
SetUpSRL;
repeat
inc(Tests)
Wait(500);
Test;
until Tests = 20;
end.


And here is the result:
Got 1
Got 0
Got 0
Got 0
Got 1
Got 0
Got 0
Got 1
Got 1
Got 1
Got 0
Got 1
Got 0
Got 0
Got 1
Got 0
Got 1
Got 0
Got 0
Got 1

Kyle Undefined

2012-04-26 11:42:57

Ah yes, you are right. I forgot that Random in PS is totally different than what I'm use to :p So I was wrong, it starts a 0 and will go up to the number passed in - 1.