SRL Archive - General Botting Help

Array of functions?


Foundry

2014-04-14 14:15:09

This is what I have:

{$include_once srlutilities\srlutilities.simba}
{$include_once wurmopengl.simba}
{$loadlib Riddler.dll}

{$f-} // Thought I might put this in to see if it would fix my problem.

type
TWurmClient = record
ID, ResX, ResY: Integer;
Name: String;
Queue: array of function: Boolean;

end;

procedure TWurmClient.switchTo();
begin
setOpenGLTarget(ID, ResX, ResY);
activateClient();
end;

function TWurmClient.init(_ID: Integer; _Name: String; _Queue: array of function: Boolean): Boolean;
var
i: Integer;
begin
Name := _Name;
Queue := _Queue;
ID := _ID;
getWindowSize(findMainWindow(ID), ResX, ResY);
ResX := ResX - 6;
ResY := ResY - 29;
switchTo();
end;

function no(): Boolean;
begin
result := false;
end;

function yes(): Boolean;
begin
result := true;
end;

function TWurmClient.cycle(): Boolean;
var
i: Integer;
begin
for i to high(Queue) do
begin
writeLn(Queue[i]);
if Queue[i] then
begin
writeLn(toStr(ID) + ' is ceding control.' + toStr(i));
break;
end;
end;
end;

var
test: TWurmClient;

begin
test.init(getPID('Wurm Online 3.'), 'charnamehere', [@no, @yes]);
test.cycle();
end.

I am trying to cycle through an array of functions and break when one of them returns true. I have tried everything I can think of to get this to work but it ends up either not compiling or not working correctly. I tried looking at SRLs waitFunc procedure but I still couldn't figure it out. Thanks in advance.

Frement

2014-04-14 14:21:18

You can try:
if (Queue()) then

Foundry

2014-04-14 14:27:45

From: Frement
You can try:
if (Queue()) then


I have tried that and I get this:

Exception in Script: Variable expected at line 63, column 33 at line 63, column 32

Frement

2014-04-14 14:34:45

From: Foundry
I have tried that and I get this:


I had to comment some stuff out, compiles and runs:
//{$include_once srlutilities\srlutilities.simba}
//{$include_once wurmopengl.simba}
{$loadlib Riddler.dll}

{$f-} // Thought I might put this in to see if it would fix my problem.

type
TBoolFunc = function: Boolean;

TBoolFuncArray = Array of TBoolFunc;

TWurmClient = record
ID, ResX, ResY: Integer;
Name: String;
Queue: TBoolFuncArray;
end;

procedure TWurmClient.switchTo();
begin
//setOpenGLTarget(ID, ResX, ResY);
activateClient();
end;

function TWurmClient.init(_ID: Integer; _Name: String; _Queue: array of TBoolFunc): Boolean;
var
i: Integer;
begin
Name := _Name;
Queue := _Queue;
ID := _ID;
getWindowSize(findMainWindow(ID), ResX, ResY);
ResX := ResX - 6;
ResY := ResY - 29;
switchTo();
end;

function no: Boolean;
begin
result := false;
end;

function yes: Boolean;
begin
result := true;
end;

function TWurmClient.cycle(): Boolean;
var
i: Integer;
begin
for i to high(Queue) do
begin
//writeLn(Queue[i]);
if Queue[i]() then
begin
writeLn(toStr(ID) + ' is ceding control.' + toStr(i));
break;
end;
end;
end;

var
test: TWurmClient;
funcs: TBoolFuncArray;

begin
setlength(funcs, 2);
funcs[0] := no;
funcs[1] := yes;
test.init(getPID(), 'charnamehere', funcs);
test.cycle();
end.

Foundry

2014-04-14 14:44:50

nvm I'm stupid -.- thanks @Frement;

Frement

2014-04-14 15:00:44

From: Foundry
nvm I'm stupid -.- thanks @Frement;


You forgot to declare the functions?

Foundry

2014-04-14 15:38:26

From: Frement
You forgot to declare the functions?


I actually tried to pass it like before [yes, no]. It works if I declare a variable and then pass the var.

Brandon

2014-04-14 16:35:47

From: Foundry
I actually tried to pass it like before [yes, no]. It works if I declare a variable and then pass the var.



No need to declare a var for every single one to get around the limitation..


Function Yes: Boolean;
Begin
Result := true;
End;

Function No: Boolean;
Begin
Result := false;
End;

Procedure Call(Query: Array of Function: Boolean);
Begin
writeln(Query[0]);
writeln(Query[1]);
writeln(Query[2]);
writeln(Query[3]);
writeln(Query[4]);
End;

var
T: Pointer;
begin
Call([T := @No, @Yes, @No, @Yes, @No, @Yes]);
end.

rj

2014-04-14 17:10:36

From: Brandon
No need to declare a var for every single one to get around the limitation..


Function Yes: Boolean;
Begin
Result := true;
End;

Function No: Boolean;
Begin
Result := false;
End;

Procedure Call(Query: Array of Function: Boolean);
Begin
writeln(Query[0]);
writeln(Query[1]);
writeln(Query[2]);
writeln(Query[3]);
writeln(Query[4]);
End;

var
T: Pointer;
begin
Call([T := @No, @Yes, @No, @Yes, @No, @Yes]);
end.


Does that code work? I recall trying to declare an array of function and having to declare each index separately
(lol as if your code wouldn't work :d)

Foundry

2014-04-14 18:05:14

From: Robert
Does that code work? I recall trying to declare an array of function and having to declare each index separately
(lol as if your code wouldn't work :d)


Yeah, that's what I meant with my earlier post. Didn't really know how to put it… Also, I just tested Brandons code and it works wonderfully.