Log in

View Full Version : How to split a TPoint?



Nebula
02-10-2012, 12:39 AM
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
02-10-2012, 12:46 AM
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
02-10-2012, 01:58 AM
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
02-10-2012, 02:05 AM
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
02-10-2012, 02:09 AM
You could also prob do

X := SPS_GetMyPos.x;

Nebula
02-10-2012, 02:18 AM
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.



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
02-10-2012, 02:22 AM
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.