SRL Archive - Help

How to split a TPoint?


Nebula

2012-02-09 19:39:08

In my script I would like to do something like this:

Begin
SPS_GetMyPos;
if (x>1200) then
begin
WalkThisPath;
end else
if (x<1166) then
begin
WalkThisPath;
end else
begin
WalkThisPath;
end;
end;

Obviously I can't do this because SPS_GetMyPos returns a TPoint, not x. How could I split the TPoint into its x and y values so that I can use them in my script? Thanks.

bg5

2012-02-09 19:46:44

var
x ,y :integer;
Point : TPoint;

begin

x:= Point.x;
y:= Point.y;

end.

For all record types like TPoint ,TBox etc. you put dot after variable like
Point.
and you will see list of all sub-elements.

Nebula

2012-02-09 20:58:15

That didn't work :/
I need to Isolate the x coordinate that SPS_GetMyPos returns.

Here is what I am dealing with:

Program SPSGetMyPos;
{$i srl/srl.simba}
{$i sps/sps.simba}
var
x, y :integer;

Procedure WalkToBank;
Begin
SPS_GetMyPos;




if (x>1200) then
begin
writeln('Walking East Path');
end else
if (x<1166) then
begin
writeln('Walking Wast Path');
end else
begin
writeln('Walking Middle Path');
end;
end;

begin
SetupSRL;
WalkToBank;
end.

Kasi

2012-02-09 21:05:54


Var
P : TPoint; // declare a local variable
Begin
P := SPS_GetMyPos; // store the results of SPS_GetMyPos into the variable

if (P.x>1200) then // your code replaced with the variable
begin
WalkThisPath;
end else
if (P.x<1166) then
begin
WalkThisPath;
end else
begin
WalkThisPath;
end;
end;

if you need to do alot of if statements just use Cases instead.

Dgby714

2012-02-09 21:09:52

You could also prob do

X := SPS_GetMyPos.x;

Nebula

2012-02-09 21:18:17

From: pur3b100d

Var
P : TPoint; // declare a local variable
Begin
P := SPS_GetMyPos; // store the results of SPS_GetMyPos into the variable

if (P.x>1200) then // your code replaced with the variable
begin
WalkThisPath;
end else
if (P.x<1166) then
begin
WalkThisPath;
end else
begin
WalkThisPath;
end;
end;

if you need to do alot of if statements just use Cases instead.


This worked, thanks.


From: Dgby714
You could also prob do
X := SPS_GetMyPos.x;


This didn't but I wish it it did since it's a bit shorter.


Thanks.

Dgby714

2012-02-09 21:22:29

From: Nebula
This worked, thanks.




This didn't but I wish it it did since it's a bit shorter.


Thanks.


Hmm Try SPS_GetMyPos().x? Sometimes it works sometimes it doesn't.
PS is real finicky about using functions that result records without a reference.