Log in

View Full Version : Arrays help?



zeeky111
01-31-2011, 04:06 AM
Okay, so I read Naum's old tut on arrays, and I set up an array test for the standard Tree.
For right now, here it is:
program ArrayTest;
{$DEFINE SMART}
{$i SRL\SRL.scar}
{$i Reflection\Reflection.simba}
var
TreeColor: Array [0..3] of Integer;
TreeUpText: Array [0..1] of String;
cx, cy, i: Integer;
{procedure SetupSMART;
begin
Smart_Server := 17;
Smart_Members := false;
Smart_Signed := true;
Smart_SuperDetail := false;
SetupSRL;
end;}
procedure DeclareVars;
begin
MouseSpeed := 15;
Writeln('Vars declared.');
end;
procedure DeclareArrayColors;
begin
TreeColor[0] := 3170902;
TreeColor[1] := 3172444;
TreeColor[2] := 5013877;
TreeColor[3] := 4882549;
Writeln('Array colors declared.');
end;
procedure DeclareUpText;
begin
TreeUpText[0] := 'ree';
TreeUpText[1] := 'Tre';
Writeln('Tree UpText strings declared.');
end;
procedure SetupScript;
begin
ClearDebug;
DeclareVars;
DeclareUpText;
DeclareArrayColors;
end;
procedure FindTreeArray;
begin
for i:= 0 to 3 do
if (FindObjCustom(cx, cy, TreeUpText, TreeColor, 5)) then
begin
Writeln('Array found at ('+IntToStr(cx)+', '+IntToStr(cy)+').');
end else
Writeln('Array not found.');
end;
begin
SetupScript
FindTreeArray;
end.
(I realize that the SMART and Reflection includes are useless to this script as of yet.)

The script compiles just fine. It declares the variables, color arrays, and UpText arrays beautifully. But when it gets to procedure FindTreeArray it stops. It doesn't cancel, exit, or terminate the script, it just does nothing and keeps running, doing nothing.

What's up here?

Thanks all.

KingKong
01-31-2011, 04:25 AM
you have merge all your procedures and make the variables local, so it looks like this:

program ArrayTest;
{$DEFINE SMART}
{$i SRL\SRL.scar}
{$i Reflection\Reflection.simba}

{procedure SetupSMART;
begin
Smart_Server := 17;
Smart_Members := false;
Smart_Signed := true;
Smart_SuperDetail := false;
SetupSRL;
end;}

procedure FindTreeArray;
var
TreeColor: Array [0..3] of Integer;
TreeUpText: Array [0..1] of String;
cx, cy, i: Integer;
begin
TreeColor[0] := 3170902;
TreeColor[1] := 3172444;
TreeColor[2] := 5013877;
TreeColor[3] := 4882549;
Writeln('Array colors declared.');

TreeUpText[0] := 'ree';
TreeUpText[1] := 'Tre';
Writeln('Tree UpText strings declared.');

for i:= 0 to 3 do
if (FindObjCustom(cx, cy, TreeUpText, TreeColor, 5)) then
begin
Writeln('Array found at ('+IntToStr(cx)+', '+IntToStr(cy)+').');
end else
Writeln('Array not found.');
end;
begin
SetupScript;
MouseSpeed := 15;
Writeln('Vars declared.');
FindTreeArray;
end.

Note: I haven't actually tested the syntax and such.

HyperSecret
01-31-2011, 06:11 AM
procedure FindTreeArray;
begin
for i:= 0 to 3 do
if (FindObjCustom(cx, cy, TreeUpText, TreeColor, 5)) then
begin
Writeln('Array found at ('+IntToStr(cx)+', '+IntToStr(cy)+').');
end else
Writeln('Array not found.');
end;


Since TreeUpText and TreeColor are arrays you need to have an index when searching for them TreeColor[i], but since where are only 2 uptexts and 4 colors you can't do that for TreeUpText, maybe looking into nested loops (using 2 for loops).

OR

Just use 1 uptext 'ree'...Let me know if you need anymore help. I will post 2 fixes...


procedure FindTreeArray;
begin
for i:= 0 to 3 do
for j:= 0 to 1 do
if (FindObjCustom(cx, cy, TreeUpText[j], TreeColor[i], 5)) then
begin
Writeln('Array found at ('+IntToStr(cx)+', '+IntToStr(cy)+').');
end else
Writeln('Array not found.');
end;


OR



procedure FindTreeArray;
begin
for i:= 0 to 3 do
if (FindObjCustom(cx, cy, 'ree', TreeColor[i], 5)) then
begin
Writeln('Array found at ('+IntToStr(cx)+', '+IntToStr(cy)+').');
end else
Writeln('Array not found.');
end;

zeeky111
01-31-2011, 07:45 PM
HyperSecret:
I tried just inputting this for the procedure FindTreeArray -
procedure FindTreeArray;
begin
for i:= 0 to 3 do
if (FindObjCustom(cx, cy, 'ree', TreeColor[i], 5)) then //*
begin
Writeln('Array found at ('+IntToStr(cx)+', '+IntToStr(cy)+').');
end else
Writeln('Array not found.');
end;
But I got a type mismatch at the line that I marked with a star.
So then I created the UpText array (TreeUpText[0..1]), and the mismatch went away.
What's up with that?

HyperSecret
01-31-2011, 08:38 PM
The parameters for that function then must take an array of string for uptext, idk for sure. I would have to look at the function to be able to tell you more.

zeeky111
01-31-2011, 11:03 PM
Here's a different example. Coincidentally, it's not working either..
function FindTree: Boolean;
begin
Text[0] := 'ree';
Text[1] := 'Tree';
Color[0] := 3432532;
Color[1] := 4485992;
Color[2] := 5077871;
Color[3] := 6529685;
Color[4] := 2645072;
Color[5] := 3168848;
for i:= 0 to 5 do
for j:= 0 to 1 do
if (FindObjCustom(cx, cy, Text[j], Color[i], 5)) then
Result := True;
end;
Here are the global vars:
var
Color: Array [0..5] of Integer;
Text: Array [0..1] of String;
cx, cy, i, j: Integer;

EDIT: The error it gives is a type mismatch at

if (FindObjCustom(cx, cy, Text[j], Color[i], 5)) then

Rich
01-31-2011, 11:07 PM
if (FindObjCustom(cx, cy, [Text[j]], [Color[i]], 5)) thenYou was using the Text and Color as normal strings and arrays, when FindObjCustom wants it a an array. I think that might do it. Not 100% sure.

zeeky111
01-31-2011, 11:50 PM
Works great, Rich.
Thanks. :3.