SRL Archive - OSR Help

Please need a little help(Out of range)


bud_wis_er_420

2012-01-02 21:04:12

I'm trying to make a procedure where when I mouse click a little red cross paints on smart to let me know where I clicked. As far as I can tell my code is all right. I've went over it like 50 times and can't seem to find the bug. Maybe an out side viewer can see what I can't seem to.

Also if you know of a shorter more neat why of doing this please let me know.

This is the error I keep getting: 'Error: Out Of Range at line 111'

program new;
{$DEFINE SMART}
{$i srl/srl.scar}
{$i SRL/SRL/misc/paintsmart.scar}
var x,y:integer;
procedure MousePaint(mousex, mousey, ranx, rany: Integer; left: Boolean);
var
CTPA :integer;
TP:Tpoint;
TPA:TPointArray;
begin
MMouse(mousex, mousey, ranx, rany);
GetMousePos(x,y)
TP := Point(x,y);
SetLength(TPA,103)

/////////////////////////////////////////////
/////////////////////////////////////////////
//Draw right
for CTPA:= 0 to 9 do
begin
TPA[CTPA]:= TP;
TP := point(TP.x+1,TP.y);
end;
///////////////////////
TP := Point(x,y-1);
for CTPA:= 10 to 17 do
begin
TPA[CTPA]:= TP;
TP := point(TP.x+1,TP.y);
end;;
///////////////////////
TP := Point(x,y+1);
for CTPA:= 18 to 25 do
begin
TPA[CTPA]:= TP;
TP := point(TP.x+1,TP.y);
end;


/////////////////////////////////////////////
/////////////////////////////////////////////
TP := Point(x,y);
//Draw down
for CTPA:= 26 to 35 do
begin
TPA[CTPA]:= TP;
TP := point(TP.x,TP.y+1);
end;
///////////////////////
TP := Point(x+1,y);
for CTPA:= 36 to 43 do
begin
TPA[CTPA]:= TP;
TP := point(TP.x,TP.y+1);
end;
///////////////////////
TP := Point(x-1,y);
for CTPA:= 44 to 51 do
begin
TPA[CTPA]:= TP;
TP := point(TP.x,TP.y+1);
end;


/////////////////////////////////////////////
/////////////////////////////////////////////
TP := Point(x,y);
//Draw left
for CTPA:= 52 to 61 do
begin
TPA[CTPA]:= TP;
TP := point(TP.x-1,TP.y);
end;
///////////////////////
TP := Point(x,y+1);
for CTPA:= 62 to 69 do
begin
TPA[CTPA]:= TP;
TP := point(TP.x-1,TP.y);
end;
///////////////////////
TP := Point(x,y-1);
for CTPA:= 70 to 77 do
begin
TPA[CTPA]:= TP;
TP := point(TP.x-1,TP.y);
end;


/////////////////////////////////////////////
/////////////////////////////////////////////
TP := Point(x,y);
//Draw up
for CTPA:= 78 to 87 do
begin
TPA[CTPA]:= TP;
TP := point(TP.x,TP.y-1);
end;
///////////////////////
TP := Point(x+1,y);
for CTPA:= 88 to 95 do
begin
TPA[CTPA]:= TP;
TP := point(TP.x,TP.y-1);
end;
///////////////////////
TP := Point(x-1,y);
for CTPA:= 96 to 103 do
begin
TPA[CTPA]:= TP;
TP := point(TP.x,TP.y-1);
end;

Wait(60 + Random(30));
SMART_DrawDotsEx(false,TPA,clRed);
ClickMouse2(left);
end;

begin
Smart_Server := 44;
SetupSRL();
MousePaint(100,100,0,0,true)
end.

euphemism

2012-01-02 21:15:44

change

for CTPA:= 96 to 103 do
to

for CTPA:= 96 to 102 do

You set the length of your TPA to 103. Arrays start at 0. 0 to 103 is 104 values, but you set the length to 103 meaning you are only working with 103 values. You do not have a 104th value to mess with, thus, it is out of range.

bud_wis_er_420

2012-01-02 21:36:28

ahh lol can't believe i missed that. Thanks