SRL Archive - OSR Help

Out of range


TsterT

2012-01-31 03:03:06


procedure DeclareVars;
Var
i, ii: Integer;
begin
ClearDebug;
SetLength(plankType, Length(players[CurrentPlayer].Arrays[0]));
ii := Length(plankType);
for i := 0 to ii do
Writeln(Capitalize(players[CurrentPlayer].Name + ' is making ' + players[CurrentPlayer].Arrays[0][i] + ' planks.'));
end;
I'm getting an out of range error on:

Writeln(Capitalize(players[CurrentPlayer].Name + ' is making ' + players[CurrentPlayer].Arrays[0][i] + ' planks.'));

It does everything it's supposed to do, but once done doing that, the script will stop.

NickMystre

2012-01-31 03:10:05

Arrays count from zero. The Length function counts from 1. Change …

 for i := 0 to ii do

to this …

 for i := 0 to ii - 1 do


EDIT: No problem. You're welcome. (BTW: We all go there at some stage - newbie or old timer! :) )

TsterT

2012-01-31 03:11:21

From: NickMystre
Arrays count from zero. The Length function counts from 1. Change …

 for i := 0 to ii do

to this …

 for i := 0 to ii - 1 do


Ahh, nice catch, didn't see that one ;).