SRL Archive - OSR Help

Ref Paths


DeSnob

2010-06-10 18:48:08

This isn't exactly to know about them , but I need help with reversing a path so that i won't need to make 2 paths. I tried
function reversePath(Tiles:TTileArray):boolean;
var
i: integer;
Path: TPointArray;
begin
Path := Tiles;
for i := High(Path) to Low(Path) do
Begin
WalkToTile(Path[i],2,0+random(6));
end;
Wait(500+Random(300));
end;

But how would i make that work? And how would i make an actual reversePath, where it doesn't walk the path but reverses it?

Narcle

2010-06-10 18:52:42

First make ur path a TPoint array then when you call WalkToTile use PointToTile(TPointArray). To reverse the path use InvertTPA(PathTPA). Using TPA's will allow you to use this function then it automatically converts the TPoints into TTiles while walking.

Sir R. M8gic1an

2010-06-10 18:56:22


Function ReversePath(Path: TTileArray): TTileArray;
var
i, h: integer;
begin
SetLength(Result, Length(Path));

h := 0;
for i := High(Path) downto Low(Path) do
begin
Result[h] := Path[i];
inc(h);
end;
end;

That'll reverse the path for you.
your problem was to rather than downto.

~RM

Narcle

2010-06-10 18:58:11

^ or that :P

3Garrett3

2010-06-10 18:58:56

By making a path, that has.. for example 5 steps:

You can say


for i := 0 to 4 do
WalkTile(path[i], 2, 1)

to walk the path forward. The following code would walk the path downward.


for i := 4 downto 0 do
WalkTile(path[i], 2, 1)

So in general:


for i := 0 to High(Path) do
WalkTile(path[i], 2, 1)

can be reversed by


for i := High(Path) downto 0 do
WalkTile(path[i], 2, 1)

Which should help you.

E: Ninja'd twice :(

Blumblebee

2010-06-10 19:13:14

why not just use InvertTPA?

DeSnob

2010-06-10 19:14:56

From: Rasta Magician

Function ReversePath(Path: TTileArray): TTileArray;
var
i, h: integer;
begin
SetLength(Result, Length(Path));

h := 0;
for i := High(Path) downto Low(Path) do
begin
Result[h] := Path[i];
inc(h);
end;
end;


That'll reverse the path for you.
your problem was to rather than downto.

~RM


Thanks! I never knew about downto. ;)

EDIT: Wouldn't this be something useful to add to the include? (Just asking :p)

masterBB

2010-06-10 19:15:05

Maybe a different question, but wich one is the standard on this forum? I currently use invertTPA.

3Garrett3

2010-06-10 19:27:20

There is really no standard for it, IMO.

If you want to make it a TPA and invert it, you can. If you want to make it a path, and use for loops, you can.

Both work, both do the same thing.

Sir R. M8gic1an

2010-06-10 19:27:38

From: masterBB
Maybe a different question, but wich one is the standard on this forum? I currently use invertTPA.


tiles are now TTiles rather than TPoints. So for good practice I guess you'd do ReversePath rather than InvertTPA

~RM

fre

2010-06-11 03:26:34

[php]
downto
[/php]

Counts down…

Drakan

2010-06-11 06:38:47

I made this function and I thought I included it, but I guess i was wrong. It will be done :)