SRL Archive - Help

Calling a function


trojan

2011-04-29 09:48:27

I made this code so that if a function fails, it is just called again 3 times. However, I think the script just takes the returned value of false from the last time the function was called or something? is there a way around this?

Procedure DoAction(Stage :variant);
begin
Repeat
if not Stage then //This calls the function.
begin
Writeln('Trying again');
Writeln('On the ' + IntToStr(Tries) + ' try');
inc(Tries);
Wait(500 + Random(500));
end else
begin
Tries := 0
Break;
end;
until (Tries > 3);
if tries > 3 then
begin
Writeln('Action Failed 4 times :/');
Logout;
Exit;
end;
end;

Rich

2011-04-29 09:53:49

It should be called each time. However, I noticed the variant parameter is also called Stage?

trojan

2011-04-29 09:59:11

I was using the variant parameter to call the required function, it would be like

DoAction(CraftRunesAlter);

I was getting in my debug box

Trying again
On the 1 try
Trying again
On the 2 try
Trying again
On the 3 try
etc…

at the beginning of the function that should have been called there was a writeln('Moving mouse to altar');

was this something to do with the way I was trying to call the function?

NCDS

2011-04-29 10:03:36

Stage will need to be a pointer, not a variant.

trojan

2011-04-29 10:11:30

How would that work though, Pointer is a Long Integer but the functions that need to be called are strings. I get a type mismatch for this anyway now
if not stage then

Edit: Would I be able to make a global variable and use that instead of passing it as a parameter?

NCDS

2011-04-29 11:36:08


Procedure DoAction(Stage :function);
begin
Repeat
if not Stage then //This calls the function.
begin
Writeln('Trying again');
Writeln('On the ' + IntToStr(Tries) + ' try');
inc(Tries);
Wait(500 + Random(500));
end else
begin
Tries := 0
Break;
end;
until (Tries > 3);
if tries > 3 then
begin
Writeln('Action Failed 4 times :/');
Logout;
Exit;
end;
end;

Would be called like

DoAction(@CraftRunesAlter); //Note the '@' symbol
I'm sure there are tutorials here on using Pointers if you care to take a look.

Yago

2011-04-29 20:40:14

Check out the function WaitFunc…

trojan

2011-04-30 04:53:49

@Yago, thank you :) this was a good example to help me understand how to pass a function

@NCDS, thanks for giving the idea of setting the data type to be a function

this is what I came up with in the end.
Procedure DoAction(stage :function :boolean);
begin
Repeat
if not (Stage()) then
begin
Writeln('Trying again');
Writeln('On the ' + IntToStr(Tries) + ' try');
inc(Tries);
Wait(500 + Random(500));
end else
begin
Tries := 0
Break;
end;
until (Tries > 3);
if tries > 3 then
begin
Writeln('Action Failed 4 times :/');
Logout;
Exit;
end;
end;