Log in

View Full Version : Calling a function



trojan
04-29-2011, 01:48 PM
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
04-29-2011, 01:53 PM
It should be called each time. However, I noticed the variant parameter is also called Stage?

trojan
04-29-2011, 01:59 PM
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
04-29-2011, 02:03 PM
Stage will need to be a pointer, not a variant.

trojan
04-29-2011, 02:11 PM
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
04-29-2011, 03:36 PM
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
04-30-2011, 12:40 AM
Check out the function WaitFunc...

trojan
04-30-2011, 08:53 AM
@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;