SRL Archive - OSR Help

General function question


doom0791

2011-03-17 03:14:57

Why does this work:

function WalkTowardTile(T : TTile) : Boolean; //Note, its T : TTile, not var T : TTile
var
Ti, Me : TTile;
Tr, tx, ty : Integer;
begin
if not LoggedIn then
Exit;
Tr := 0;
Debug('Can''t find next tile. Trying to walk closer.');
while not TileOnMM(T) do
begin
Me := GetMe.Tile;
tx := (T.x - Me.x)/2 + Me.x;
ty := (T.y - Me.y)/2 + Me.y;
Ti := Tile(tx, ty);
if TileOnMM(Ti) then
WalkToTile(Ti, 3, 1)
else
T := Ti; //I reset the parameter T
if Tr > 5 then
begin
Result := False;
Exit;
end;
end;
Result := True;
end;

I want to know because I've been having problems with my miner & banker lately and I think this may be the issue. The script runs great for awhile, then crashes with a black SMART screen after awhile.

Can anyone explain to me what exactly is going on when this happens (resetting a parameter in a function like shown above)? I always thought it'd give a compiler error.

TomTuff

2011-03-17 03:16:07

Why don't you just add a new variable (A TTile) and set NewTile := Ti, then use it from there?

doom0791

2011-03-17 03:19:19

From: TomTuff
Why don't you just add a new variable (A TTile) and set NewTile := Ti, then use it from there?


Thanks, I intend to do that later.

I'd really like to know what's going on though, just for the sake of knowing. I guess it just irks me to not know why something works when it shouldn't. ;)

TomTuff

2011-03-17 03:22:06

From: doom0791
Thanks, I intend to do that later.

I'd really like to know what's going on though, just for the sake of knowing. I guess it just irks me to not know why something works when it shouldn't. ;)


It shouldn't, but it still happens, thus why it's a bug.