SRL Archive - OSR Help

Declaring constant array of Integers


djborec

2012-08-22 14:10:34

How do I declare constant array of integers?

I tried:

const
worlds:array[1..5] of Integer=(5,6,9,18,21);

and its not working…


Also has Simba something like EOL (End Of Line) as it used to be in Pascal while reading files….?

Home

2012-08-22 14:14:40

program new;

var
TIA :TIntegerArray;

begin
TIA := [5,6,9,18,21]
end.


~Home

eska

2012-08-22 14:51:34

I think what home is trying to say is that you can't make constant arrays of integers in pascal script, and so you need to use a variable instead.

I do beleive constant integer array are supported in lape.

Kasi

2012-08-22 14:52:12


Const
P = [9, 0, 0, 4, 34];

lol just tried it, it actually doesnt let you, learn something new everyday -.-, ignore this post

mormonman

2012-08-22 15:34:39

Lape can do it
program default;

const
i = [1,1];

begin
writeln(tostr(i));
end.

djborec

2012-08-25 18:04:31

with Pascal script how do I add another number to TIntegerArray

do I have to use soemthing like:

Array[Length(Array)]:=number; or is there function for this?

Runaway

2012-08-25 18:11:35

From: djborec
with Pascal script how do I add another number to TIntegerArray

do I have to use soemthing like:

Array[Length(Array)]:=number; or is there function for this?


You have to increase the length of the array before you can store a new value:


var
Arr: TIntegerArray;
begin
Arr := [1, 2, 3];

// Example 1:
Arr := [1, 2, 3, 4];

// Example 2:
SetLength(Arr, Length(Arr) + 1);
Arr[High(Arr)] := 4;

end;

djborec

2012-08-25 19:05:19

Runaway thanks,

so there is nothing as dynamic array in Pascal script?

x[Warrior]x3500

2012-08-25 19:46:37

From: djborec
Runaway thanks,

so there is nothing as dynamic array in Pascal script?


nope, but in Lape we have access to pointers/ref. so we can create linked lists if we wanted.

masterBB

2012-08-25 20:20:03

From: x[Warrior]x3500
nope, but in Lape we have access to pointers/ref. so we can create linked lists if we wanted.


When lape is option anyway…

program new;

type
TSuperIntegerArray = record
val: TIntegerArray;
end;

var
a: TSuperIntegerArray;

procedure TSuperIntegerArray.push(v: Integer);
begin
SetLength(Self.val, Length(Self.val) + 1);
Self.val[High(Self.val)] := v;
end;

begin
a.push(3);
a.push(4);
writeln(a.val);
end.

riwu

2012-08-25 20:25:00

There is a very simple way: Set the length to a very high number, then you can freely add to it, and when you want to use it (such as when looping through the integers), you can just delete the integers with value 0. Will not work if there is a chance that your intended value is 0 though.

NCDS

2012-08-25 20:53:09

with PascalScript

var
TIA: array of TIntegerArray;
begin
tia := [[TIntegerArray([1, 2])], [TIntegerArray([3, 4])], etc];
end;