SRL Archive - Reflection Help

Please review this piece of code :)


The Little

2009-06-23 19:09:24

Hey all,

I just started on my first Reflection project, a barbarian outpost agility course runner :P. Since this is my first script using Reflection I have no idea what it should look like. So would someone please review this procedure? Its for finding the first obstacle of the barbarian outpost course (the rope).

procedure RopeSwing;
var
MyPosition, MSPoint : TPoint;
begin
MyPosition := GetMyPos;

if not ((MyPosition.x = RopeFront.x) and (MyPosition.y = RopeFront.y)) then
Exit;

if not FindObjectEx(RopePoint, RopeID, 2) then
Exit;

MSPoint := TileToMS(RopePoint, 260);
MMouse(MSPoint.x, MSPoint.y, 10, 5);

if IsUpText('ing') then
begin
WriteLn('Clicking rope using Reflection');
GetMousePos(MSPoint.x, MSPoint.y);
Mouse(MSPoint.x, MSPoint.y, 0, 0, False);
R_ChooseOption('Swing-on');
end else
begin
WriteLn('Rope not found, switching to color');
if FindColorTolerance(MSPoint.x, MSPoint.y, 470838, 255, 210, 290, 230, 10) then
begin
MMouse(MSPoint.x, MSPoint.y, 3, 15);
if IsUpText('ing') then
begin
WriteLn('Clicking rope using Color');
GetMousePos(MSPoint.x, MSPoint.y);
Mouse(MSPoint.x, MSPoint.y, 0, 0, False);
R_ChooseOption('Swing-on');
end else
begin
WriteLn('Did not click because uptext did not match.')
Exit;
end
end else
begin
WriteLn('Object color not found either. Exiting.');
Exit;
end;
end;
end;

The variables I'm using for object location and ID are declared outside the procedure. There are no failsafes for failing the obstacle yet, I just want to know if I'm heading in the right direction :).

Thanks :)

Quickmarch

2009-06-23 19:46:27

Looks great for a first script. :) Definitely heading in the right direction. :)

The Little

2009-06-23 19:54:22

Thanks :), just wanted to be sure as it wouldn't be the first time my code turns out to be useless just after I finished it… :P

Floor66

2009-06-23 21:16:32

If I may ask, do you come from another coding language?
Because, you learn fast afaik and your indenting looks like you've coded before.

I suggest reading up to some SCAR standards, because they are a little different from others'.

E.G: you indent with 2 spaces.

The Little

2009-06-23 21:32:17

Coded in C before :), never knew about the indenting, I'll read the tut I found about SCAR standards ;), thanks.

EDIT: Fixed the indenting, thanks again ;)

ZaSz

2009-06-23 22:36:15

Looks like you been using some of my tutorial :)

Lookin good.

The Little

2009-06-23 22:43:10

Looks like you been using some of my tutorial

Lookin good.

Yep, I used FindObjectEx to speed it up a little though, Script itself is coming along pretty well, but I'm still learning so it will probably take a while :/