SRL Archive - SRL Old School RuneScape

Variable help


Too Soon

2013-11-21 17:14:06

Alright so I'm trying to re-mimic the procedure
procedure GetMousePos(var x,y: integer);

An example of GetMousePos is

program getMousePos;

var x,y: integer;
begin
GetMousePos(x,y);
ClickMouse(x,y,true);
end.

It stores the mouse position in variable X and Y.
What do you do to store output on the input variable? When I try I get an Access Violation error.

riwu

2013-11-21 17:42:46

What do you mean by mimicking the procedure? overriding/overloading it?

Third argument of ClickMouse() should be an Integer (use MOUSE_LEFT/MOUSE_RIGHT constants if you are using ogl/srl include)

Too Soon

2013-11-21 17:58:10

I'm trying to make a procedure that will store output on the input variables like GetMousePos does.
ClickMouse(x,y,0); oops sorry.

bonsai

2013-11-21 19:07:11

That's what the 'var' is in the procedure/function line. var means changes will get changed in the caller variable.

No var means any changes inside the function do not get changed in the caller.

Neither one should cause an access violation. You would have to post some code for an explanation of the issue.

Too Soon

2013-11-22 08:03:27

From: bonsai
That's what the 'var' is in the procedure/function line. var means changes will get changed in the caller variable.

No var means any changes inside the function do not get changed in the caller.

Neither one should cause an access violation. You would have to post some code for an explanation of the issue.



Thanks for this. That really helped.
I guess the violation error is something irrelevant to my question, but here's my code. Thank you very much in advance.

program keyListener;
var x,y:integer;
a,b,c: TPoint;
ab: TPointArray;

function keyListener(key,time: integer): TPoint;
var loopBack,tx,ty: integer;
begin
loopBack := GetTimeRunning + time;
writeLn('Loop time: ' + intToStr(time));
while(loopBack > GetTimeRunning) do
begin
if (isKeyDown(key)) then
begin
GetMousePos(tx,ty);
writeLn('Mouse Position: {X:' + intToStr(tx)
+ ' Y:' + intToStr(ty) + '}');
result := Point(tx,ty);
sleep(time div 2);
end;
end;
end;

procedure setValue(var keyL: TPoint; tpa: TPointArray; number: integer);
begin
tpa[number] := keyL;
end;

begin
setValue(keyListener(112,10000),ab,nextAvaliableLine);
end.

What I'm trying to do is get the mouse position (TPoint keyListener) and store it on an array (TPointArray ab) on the next available line of that array. (line 0 of array ab. (ab[0]))

riwu

2013-11-22 08:18:47

You need to increase the length of your tpa before you can add more elements to it.

SetLength(tpa, Length(tpa) + 1);
tpa[High(tpa)]:= keyL;

bonsai

2013-11-22 08:37:53

Also, you have the var on the wrong variable.

procedure setValue(var keyL: TPoint; tpa: TPointArray; number: integer);
begin
tpa[number] := keyL;
end;

Since you're changing tpa, it should be more like:

procedure setValue(keyL: TPoint; var tpa: TPointArray; number: integer);
begin
tpa[number] := keyL;
end;

barty180

2013-12-03 23:04:36

you guys are so smart =]