SRL Archive - OSR Help

Waitfunc inside other function


bg5

2012-01-04 01:48:31

How to put WaitFunc inside other function?

I was trying…

program new;
{$DEFINE SRL5}
{$i srl/srl.simba}

function Test (Func: function : boolean) : Boolean ;
begin
if (WaitFunc(@func,100,5000)) then
writeln ('something');
end;

begin
end.

[Error] (8:17): Unknown identifier 'func' at line 7

and

program new;
{$DEFINE SRL5}
{$i srl/srl.simba}

function Test (Func: function) : Boolean ;
begin
if (WaitFunc(@func,100,5000)) then
writeln ('something');
end;

begin
end.
[Error] (6:30): colon (':') expected at line 5

and

program new;
{$DEFINE SRL5}
{$i srl/srl.simba}

function Test (Func: function : boolean) : Boolean ;
begin
if (WaitFunc(func,100,5000)) then
writeln ('something');
end;

begin
end.
[Error] (8:32): Type mismatch at line 7

I have really no idea. Anyone could help?

wantonman

2012-01-04 02:56:33



program new;
{$i srl/srl.scar}



function CallSelf: Boolean;
begin
if CallSelf then
result:= True;
end;


function Yeah: string;
begin
if callSelf then
result:= 'Yeah';
end;




begin
writeln(Yeah);
end.



http://villavu.com/forum/showthread.php?t=59061


http://villavu.com/forum/showthread.php?t=54716


http://villavu.com/forum/showthread.php?t=47134

bg5

2012-01-04 04:00:21

Hmm…I don't understand. Could you make example with WaitFunc?

http://villavu.com/forum/showthread.php?t=59061


http://villavu.com/forum/showthread.php?t=54716


http://villavu.com/forum/showthread.php?t=47134
Reply With Quote


thanks for link ,but i can't find answer there.



@ edit

At last i can do something like:
program new;
{$DEFINE SRL5}
{$i srl/srl.simba}

function Test (Func: function : boolean) : Boolean ;
var
T, WaitPerLoop, MaxTime: Integer;
Result_WF : boolean;
begin

/////////WaitFunc////////////////
T := GetSystemTime + MaxTime;
while (GetSystemTime < T) do
begin
if (Func()) then
begin
Result_WF := True;
Exit;
end;
Wait(WaitPerLoop);
end;
/////////end of WaitFunc/////////

if (Result_WF) then
writeln ('something');
end;

But it's ugly;)

wantonman

2012-01-04 16:58:03

you should really try and follow the proper structure of a function





{$i srl\srl.scar}



function Foundcolor: Boolean;
var
x,y:integer;
begin
if
findcolor(x, y, 111111, 1,1,520,340 ) then
begin
result:=true
end;
end;



begin
repeat
Waitnone;
//until Wait until we found the color...
until(WaitFunc(@FoundColor, 8000+ Random(15), 9000));
end.




make your own function



//this type of function is called a boolean, meaning it can either be true or false
Function NameOfFunction: Boolean;
Begin
If findColor(x, y, 111111, 1,1,520,340)then
Begin
Result:=True
End;


//when using a function in your script you simply put the name

repeat
writeln('waiting')
//until the color is found
until(NameOfFunction)




have you any programming experience?
it may be tough but try reading any book on programming
try Java…
youll eventually will be more familiar…
Personally I like Python because it has PyGame =)

Kyle Undefined

2012-01-04 17:33:10

wantonman, your structure, or "standards" are horrible. Beginner had them right.

wantonman

2012-01-04 17:41:40

okay even if i dont its still good to mention it………. :sasmokin:

bg5

2012-01-05 11:31:43

have you any programming experience?
it may be tough but try reading any book on programming


It's really strange you said that ,because you misunderstood my problem. I didn't ask about making basic function , my question was clear:
How to put WaitFunc inside other function?


And the code you showed me will do nothing, because callself is always false. I'm not going to be rude ,but if you really want to help somebody you should take more care about your answers ,and what's a point of question. I'm sure you didn't even compile this:

program new;
{$i srl/srl.scar}

function CallSelf: Boolean;
begin
if CallSelf then // so if False then True ? :)
result:= True;
end;

function Yeah: string;
begin
if callSelf then // if False...
result:= 'Yeah';
end;

begin
writeln(Yeah); // write empty string and stuck script in infinity loop !
end.

Kyle Undefined

2012-01-05 12:04:12

You're basically trying to make a wrapper, why not just use "WaitFunc" where needed?

wantonman

2012-01-05 15:07:47

i did put it inside another function and i gave you multiple examples:spongebob::spongebob::spongebob::spongebob::spongebob::spongebob::spongebob::spongebob::spongebob::spongebob::spongebob::spongebob::spongebob::spongebob::spongebob::spongebob::spongebob:

bg5

2012-01-05 15:35:45

From: Kyle Undefined
You're basically trying to make a wrapper, why not just use "WaitFunc" where needed?


I need to put WaitFunc inside more complicated function ,not only wrapper. My example script was only for testing :P

Kyle Undefined

2012-01-05 16:25:14

Ah I see now, there's no way you can use WaitFunc there without having to make another function?

Dgby714

2012-01-05 16:30:45

From: beginner5
How to put WaitFunc inside other function?

I was trying…

program new;
{$DEFINE SRL5}
{$i srl/srl.simba}

function Test (Func: function : boolean) : Boolean ;
begin
if (WaitFunc(@func,100,5000)) then
writeln ('something');
end;

begin
end.

[Error] (8:17): Unknown identifier 'func' at line 7

and

program new;
{$DEFINE SRL5}
{$i srl/srl.simba}

function Test (Func: function) : Boolean ;
begin
if (WaitFunc(@func,100,5000)) then
writeln ('something');
end;

begin
end.
[Error] (6:30): colon (':') expected at line 5

and

program new;
{$DEFINE SRL5}
{$i srl/srl.simba}

function Test (Func: function : boolean) : Boolean ;
begin
if (WaitFunc(func,100,5000)) then
writeln ('something');
end;

begin
end.
[Error] (8:32): Type mismatch at line 7

I have really no idea. Anyone could help?


You can't, seems there is a bug in PascalScript preventing the passing of a function pointer more than once.

wantonman

2012-01-05 17:12:39

perhaps putting the @ symbol waitfunk(@funk… harhar just because you cant figure it out does not mean the entire pascal scripting language is dead!
You can't, seems there is a bug in PascalScript preventing the passing of a function pointer more than once.
:spongebob::spongebob::spongebob:


This writes something

program new;
{$DEFINE SRL5}
{$i srl/srl.simba}




function Zero : Boolean ;
begin
MoveMouse ( 640 , 420 )
end ;




function One : Boolean ;
begin
if WaitFunc ( @ Zero , 100 , 5000 ) then
Result := True ;
end ;









function Two : Boolean ;
begin
WaitFunc ( @ One , 100 , 10000 )
writeln ( 'something' ) ;
end ;





procedure Proced ;
Begin
Two ;
One ;
Zero ;
end ;


begin
proced ;
end.
Wait Function waits for a function to be true. So you said have it in a function? Sure why not? You can.

It just equals the result of it, thats all. Either it will wait for the function to be true or false. Weather or not it still results it still would have completed the function, get me? Either way it still is going to be true.

I dont know if that is what your asking.:spongebob::spongebob::spongebob:

bg5

2012-01-05 17:49:24

You can't, seems there is a bug in PascalScript preventing the passing of a function pointer more than once.


That's bad news ,so I will have to integrate waitfunc with two superior funcions ,joining 3 in one :D It seems crazy.

Is there no way to bypass this bug?



@wantonman

function One : Boolean ;
begin
if WaitFunc ( @ Zero , 100 , 5000 ) then
Result := True ;
end ;

function Two : Boolean ;
begin
WaitFunc ( @ One , 100 , 10000 )
writeln ( 'something' ) ;
end ;

Not Waitfunc inside Waitfunc ,but: put to WaitFunc @function given as argument to superior function like:

function Two (Func : function : boolean) : Boolean ;
begin
WaitFunc ( @ Func , 100 , 10000 );
writeln ( 'something' ) ;
end ;

begin
Two(@One);
end.

Dgby714

2012-01-05 18:28:05

From: beginner5
That's bad news ,so I will have to integrate waitfunc with two superior funcions ,joining 3 in one :D It seems crazy.

Is there no way to bypass this bug?


Write your own WaitFunc? It's actually a really simple function.

bg5

2012-01-05 19:32:53

Write your own WaitFunc? It's actually a really simple function.


You mean function which does the same as WaitFunc? I really have no idea how to put function as argument to second function in other way then waitfunc does (func :function: boolen).

for example:

function WaitFunc2(Func : Boolean ; WaitPerLoop, MaxTime: Integer): Boolean;
var
T: Integer;
begin
T := GetSystemTime + MaxTime;
while (GetSystemTime < T) do
begin
if (Func) then
begin
Result := True;
Exit;
end;
Wait(WaitPerLoop);
end;
end;

begin
Waitfunc2(Checker,10,10000);
end.

not works ,because it execute Func only once. Maybe it's easy ,but not for me.

Dgby714

2012-01-05 19:42:47

From: beginner5
You mean function which does the same as WaitFunc? I really have no idea how to put function as argument to second function in other way then waitfunc does (func :function: boolen).

for example:

function WaitFunc2(Func : Boolean ; WaitPerLoop, MaxTime: Integer): Boolean;
var
T: Integer;
begin
T := GetSystemTime + MaxTime;
while (GetSystemTime < T) do
begin
if (Func) then
begin
Result := True;
Exit;
end;
Wait(WaitPerLoop);
end;
end;

begin
Waitfunc2(Checker,10,10000);
end.

not works ,because it execute Func only once. Maybe it's easy ,but not for me.


function WaitFunc2(Func : Boolean ; WaitPerLoop, MaxTime: Integer): Boolean;

needs to be

function WaitFunc2(Func: function: Boolean; WaitPerLoop, MaxTime: Integer): Boolean;

and

Waitfunc2(Checker,10,10000);

needs to be

Waitfunc2(@Checker,10,10000);

Dgby714

2012-01-05 19:53:52

Actually I just remembered, you may want something like this.

http://villavu.com/forum/showpost.php?p=763015&postcount=9

bg5

2012-01-05 20:02:51

Actually I just remembered, you may want something like this.

http://villavu.com/forum/showpost.ph...15&postcount=9


Wow ,your function is beast ,it really helped me with everything :) TYVM

Why it's not in SRL?

Dgby714

2012-01-05 20:19:54

From: beginner5
Wow ,your function is beast ,it really helped me with everything :) TYVM

Why it's not in SRL?


No one has added it yet? I don't use SRL so I didn't send it in…