mxtrix
2014-07-28 00:40:50
Hey guys, this error has stumped me completely. I have fixed up https://villavu.com/forum/showthread.php?t=76643 and it works great however when trying to incorporate it into an existing script I get a weird exception. This script runs fine:
However when adding it to bonsaiFighter I get the error Exception in Script: Can't assign "function():Int32" to "Int32" at line 69, column 7 in file "C:\Simba\Includes\grabber.simba".
The source for the grabber.simba file is: (again- it runs fine as part of the script above but throws that error when called from bonsai's script.
I cannot seem to find any plausible explanation as to why this is occurring.
program HenHouseBones;
{$DEFINE SMART}
{$I SRL-6/SRL.simba}
{$I SPS/lib/SPS-RS3.Simba}
{$I grabber.simba}
function SetupLoots : Array of TLoot;
begin
SetLength(Result,1);
Result[0].name := ['Carapace','arapace'];
Result[0].color := 1735873;
Result[0].tol := 6;
Result[0].CTS := 2;
Result[0].cts2Hue := 1.41;
Result[0].cts2Sat := 4.64;
end;
procedure start;
begin
SetupSRL;
end;
begin
start;
//Writeln(tabBackpack.count());
LootGrabber(SetupLoots,TRUE,['Take Coins','oins','ake']);
Writeln('We got that loot');
end.
However when adding it to bonsaiFighter I get the error Exception in Script: Can't assign "function():Int32" to "Int32" at line 69, column 7 in file "C:\Simba\Includes\grabber.simba".
The source for the grabber.simba file is: (again- it runs fine as part of the script above but throws that error when called from bonsai's script.
type TLoot = record
name : TStringArray;
CTS ,color ,tol: integer;
cts2Sat , cts2Hue : extended;
end;
{
function SetupLoots_Example : Array of TLoot;
begin
SetLength(Result,2);
Result[0].name := ['one','ones'];
Result[0].color := 13948895;
Result[0].tol := 5;
Result[0].CTS := 2;
Result[0].cts2Hue := 0.76;
Result[0].cts2Sat := 1.22;
Result[1].name := ['egg','gg'];
Result[1].color := 13948895;
Result[1].CTS := 2;
Result[1].cts2Hue := 0.76;
Result[1].cts2Sat := 1.22;
end;
}
function CombineStrA (a ,b :TStringArray) : TstringArray;
var
h1 ,h2 ,i : integer;
begin
h1 := High(a);
h2 := High(b);
setLength(Result,h1+h2+2);
for i:= 0 to h1 do
Result[i] := a[i];
for i:= 0 to h2 do
Result[i+h1+1] := b[i];
end;
function CountOptionsMulti(Texts: TStringArray; TextType: String): integer;
var
i, LO, ii, LT, x: Integer;
T: TPoint;
Options: array of TOption;
begin
Options := ChooseOption.getOptions();
if (Length(Options) < 1) then
Exit;
LO := High(Options);
LT := High(Texts);
for i := 0 To LO do
begin
for ii := 0 to LT do
If Pos(Texts[ii], Options[i].Str) > 0 Then
begin
Result := Result+1;
break;
end;
end;
end;
function LootFinder(Loots : array of TLoot ; Debug : Boolean) : T2dPointArray;
var
tATPA : T2dPointArray;
a, h : integer;
cts : integer;
begin
cts := Gettolerancespeed;
h := high(Loots);
SetLength(tATPA,2);
for a := 0 to h do
begin
SetColorToleranceSpeed( Loots[a].CTS );
SetToleranceSpeed2Modifiers(Loots[a].cts2Hue , Loots[a].cts2Sat);
Findcolorstolerance(tATPA[1],Loots[a].color ,mainscreen.getBounds ,Loots[a].tol);
CombineTPAwrap(tATPA[0],tATPA[1],tATPA[0]);
end;
splitTPAExwrap(tATPA[0],11,11,Result); // now you have ready-made ATPA of loots ,you can do
// whatever you want with it, like sorting etc.
SetColorToleranceSpeed(cts);
end;
function LootGrabber (Loots : array of TLoot; Debug:Boolean; ListOfUndesirable : TStringArray) : boolean;
var
a ,b,HCount ,itemC ,h, FalseAlarm, tmpcnt :integer;
tempP :TPoint;
str ,str2: TStringArray;
ATPA : T2dPointArray;
begin
ATPA := LootFinder(Loots,Debug);
h := High(Loots);
if (h = 0) then
str := Loots[0].name
else
for a:= 0 to h-1 do
str := CombineStrA(Loots[a].name,Loots[a+1].name);
str2 := CombineStrA (str ,ListOfUndesirable);
HCount := High(ATPA);
if((HCount)<>(-1)) then
begin
for a:= 0 to HCount do
begin
tempP := ATPA[a][random(Length(ATPA[a]))];
Mouse(tempp.x,tempp.y,0,0);
if (tabBackpack.isFull) then
begin
writeln('LootGrabber :: Inventory full ,exiting');
exit;
end;
if isMouseOverText(str2,600 ) then
begin
fastClick(MOUSE_RIGHT);
wait(300);
itemC := CountOptionsMulti(str,'all');
if itemC <> 0 then
begin
if debug then writeln('LootGrabber :: Found number of items in pile :'+tostr(itemC/2));
wait(100+random(200));
ChooseOption.Select(str);
Result := true;
tmpcnt := tabBackpack.count();
//Minimap.isPlayerMoving(8000); // this handle time between click on object and taking it
tabBackpack.waitForShift(10000); // you can replace it with another function like checking if new item was added to inv
if (itemC > 2) then
begin
wait(500+random(200));
for b := 2 to Round(itemC/2) do // take + examine item = 2
begin
if (tabBackpack.isFull) then exit;
wait(200+random(200));
Mouse(257,172+random(5),0,0);
fastClick(MOUSE_RIGHT);
wait(50+random(50));
ChooseOption.Select(str);
end;
end;
break;
end else
begin
if debug then writeln('LootGrabber :: Wrong items on pile!');
Inc(FalseAlarm);
end;
end else
begin
if debug then writeln('LootGrabber :: Wrong item here!');
Mouse(257,172,0,0);
Inc(FalseAlarm);
end;
end;
end else
begin
writeln('LootGrabber :: No objects found ,exiting!');
Exit;
end;
wait(500+random(500));
If (Hcount > FalseAlarm ) then
LootGrabber(Loots ,Debug,ListOfUndesirable); // repeat if any loot left
end;
I cannot seem to find any plausible explanation as to why this is occurring.