SRL Archive - Jr. Member General Help and Discussion

Exception in Script: Can't assign "function():Int32" to "Int32"


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:

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.

KeepBotting

2014-07-28 06:59:20

What's line 69?

mxtrix

2014-07-28 08:06:27

cts := Gettolerancespeed; It occurs when I try to make something equal to a function- for example a boolean function which returns true or false. Setting a boolean to equal the function would return an error as apparently the result from a function is of type function():Int32 instead of Int32.

KeepBotting

2014-07-28 08:13:08

From: mxtrix
cts := Gettolerancespeed; It occurs when I try to make something equal to a function- for example a boolean function which returns true or false. Setting a boolean to equal the function would return an error as apparently the result from a function is of type function():Int32 instead of Int32.


Yeah I don't think you can assign the result of a function to anything. Never mind that, the entire LootFinder() function is still SRL-5 code, soooooo

mxtrix

2014-07-28 08:18:13

From: KeepBotting
Yeah I don't think you can assign the result of a function to anything. Never mind that, the entire LootFinder() function is still SRL-5 code, soooooo


You can, the code runs fine when called from a new simba script but only bonsai's causes his error. I updated it myself to SRL6. You are trying to say that this is not valid:

freeSlots := (28 - tabBackpack.count());

KeepBotting

2014-07-28 08:20:10

From: mxtrix
You can, the code runs fine when called from a new simba script but only bonsai's causes his error. I updated it myself to SRL6. You are trying to say that this is not valid:

freeSlots := (28 - tabBackpack.count());
Meh I'm not sure of that

My point is that your entire LootGrabber() function is still srl-5

mxtrix

2014-07-28 08:23:23

From: KeepBotting
Meh I'm not sure of that

My point is that your entire LootGrabber() function is still srl-5


It compiles and runs fine with SRL6. The first script in the OP runs fine- the function is not the problem. The problem is that the logic used in freeSlots := (28 - tabBackpack.count()); does not work when I include it into bonsai's script and I cannot seem to find a reason for this when it works fine in any other one. I have searched his script and cannot see any changed which would cause the type difference.

KeepBotting

2014-07-28 08:50:34

From: mxtrix
It compiles and runs fine with SRL6. The first script in the OP runs fine- the function is not the problem. The problem is that the logic used in freeSlots := (28 - tabBackpack.count()); does not work when I include it into bonsai's script and I cannot seem to find a reason for this when it works fine in any other one. I have searched his script and cannot see any changed which would cause the type difference.

Ugh, sorry it's really early. You're right.


Just use this for getting free slots:

function getFreeSlots():TIntegerArray;
var
theArray:TIntegerArray;
i:integer;
begin
if (not gameTabs.isTabActive(TAB_BACKPACK)) then
gameTabs.openTab(TAB_BACKPACK);

for i := 1 to 28 do
begin
if not tabBackpack.isItemInSlot(i) then
begin
theArray.append(i);
end;
end;
writeDebug('Free backpack slots are: ' + toStr(theArray));
result := theArray;
end;

Then do
freeSlots := (length(getFreeSlots));

bonsai

2014-07-28 14:17:29

I suspect the problem is that I use "{$f-}" at the top of all my script files.

This requires that you use parenthesis when calling functions and makes some difference in how you handle pointers.