SRL Archive - OSR Help

Passing Functions through Functions


smurg

2011-02-04 19:32:38

I think I remember seeing something about passing a function through a function using the @ symbol?

Basically, I run this code block a lot:


Start := GetSystemTime;
repeat
Wait(100);
if((GetSystemTime - Start) > 7500)then
begin
Failsafe(False);
Break;
end;
until(not(R_BankScreen))

So I want to make a function allowing myself to input a value instead of the 7500 for the Breakout time, and then the until() condition.

But you can't just do WhateverFunction(7500, not(BankScreen)) because that will run the function and actually pass the result through correct?

Would it be: WhateverFunction(7500, @not(BankScreen)) ?

Can't test atm, have a sick proggy going.

Frement

2011-02-04 19:34:48

I would say it would be:
WhateverFunction(7500, not(@BankScreen))
I have never tried it before, theres a tutorial on it thought, can't remember who wrote it.

Awkwardsaw

2011-02-04 20:44:09

you might have to do


bool := bankscreen;

or

if bankscreen then
bool := true;

then

whateverfunction(bool)

Nava2

2011-02-04 20:53:27

function WaitFor(f: function: Boolean; timeout: Integer):Boolean;
var
time: Integer;
begin
time := GetSystemtime;
while ((not f) and (time-GetSystemtime > timeout)) do
wait(16+Random(40));
end;

//..
waitfor(@bankscreen, 2000);

Pretty sure this is already in SRL too.

smurg

2011-02-04 21:41:19

From: Awkwardsaw
you might have to do

Simba Code:
[LEFT]bool := bankscreen;
[/LEFT]


or Simba Code:
[LEFT]if bankscreen then
bool := true;
[/LEFT]


then
Simba Code:
[LEFT]whateverfunction(bool)
[/LEFT]



That's the same as just passing the function as a parameter, which is what I don't want to do.

I want the function to run inside the main function, not before and pass a value into it.

From: Nava2
Simba Code:
[LEFT]function WaitFor(f: function: Boolean; timeout: Integer):Boolean;
var
time: Integer;
begin
time := GetSystemtime;
while ((not f) and (time-GetSystemtime > timeout)) do
wait(16+Random(40));
end;

//..
waitfor(@bankscreen, 2000);

[/LEFT]


Pretty sure this is already in SRL too.



Exactly. It doesn't show up in the FunctionList and I have SRL included, possibly a misc include?

Anyways I'll just use my own. Do you happen to know to do it for the reverse condition?

Just ?:

waitfor(@(not bankscreen), 2000);

Nava2

2011-02-04 22:26:47

From: smurg
That's the same as just passing the function as a parameter, which is what I don't want to do.

I want the function to run inside the main function, not before and pass a value into it.




Exactly. It doesn't show up in the FunctionList and I have SRL included, possibly a misc include?

Anyways I'll just use my own. Do you happen to know to do it for the reverse condition?

Just ?:

waitfor(@(not bankscreen), 2000);


No, but its in Timing.scar.

You can't pass it like that. Look up `procedural functional pointers` in the tutorial island.