SRL Archive - Reflection Help

Reflection variables


DeSnob

2010-06-06 20:46:00

I know the following error has to do with reflection, but since I'm not familiar to it I can't figure out what to do! In my procedure,
function MineRocks(rock:string): boolean;
var
P: TPoint;
Obj: TRSObject;
begin
case lowercase(rock) of
'tin': Obj := GetObjectsByID([11935, 11933, 11553, 11934, 11552], 0, 0);
'copper': Obj := GetObjectsByID([11938, 11936, 11937], 0, 0);
end;
P := TileToMS(Obj.Tile, 10);
case random(100) of
0..50: Mouse(p.x, p.y, 0, 0, True);
51..99: Mouse(p.x, p.y, 0, 0, True);
end;
end;
[Error] (90:74): Type mismatch at line 89
Compiling failed.
I'm seriously stuck here. I've checked everywhere in the includes! :(

Nava2

2010-06-06 21:22:56

Which is line 89?

DeSnob

2010-06-06 21:44:36

From: Nava2
Which is line 89?


'tin': Obj := GetObjectsByID([11935, 11933, 11553, 11934, 11552], 0, 0);
It has something to do with obj, and finding multiple objects

Nava2

2010-06-06 22:06:58

getObjectsByID;

;)

It returns an array iirc.

DeSnob

2010-06-06 22:23:27

From: Nava2
getObjectsByID;

;)

It returns an array iirc.


I understand that, but how can i make it work is the question. I already knew it was to be multiple, thing is I want it to look for all of the tin/copper rocks and not just one

Nava2

2010-06-06 22:34:54

Have your variable as an array, and the function already returns them in order of distance from you. So, you could just check each one in the array using a for..to..do loop. :)

DeSnob

2010-06-06 22:36:17

From: Nava2
Have your variable as an array, and the function already returns them in order of distance from you. So, you could just check each one in the array using a for..to..do loop. :)


So like, a TRSObjectArray? I'll work with that :D

EDIT: THANK YOU SOO MUCH :)

function MineRocks(rock:string): boolean;
var
i: integer;
P: TPoint;
Obj: TRSObjectArray;
begin
case lowercase(rock) of
'tin': Obj := GetObjectsByID([11935, 11933, 11553, 11934, 11552], 0, 0);
'copper': Obj := GetObjectsByID([11938, 11936, 11937], 0, 0);
end;
for i := 0 to High(Obj) do
begin
P := TileToMS(Obj[i].Tile, 0);
MMouse(p.x, p.y, 0, 0);
if (R_IsUpText('Mine')) then
begin
case random(100) of
0..50: Mouse(p.x, p.y, 0, 0, True);
51..99:
begin
Mouse(p.x, p.y, 0, 0, False);
R_ChooseOption('Mine');
end;
end;
end;
end;
end;

Nava2

2010-06-07 12:38:15

You need to break out after you click the rock ;)

Sir R. M8gic1an

2010-06-07 15:00:53

Good job ;)

~RM