Jump to content
randomphobia

scar version of list/array

Recommended Posts

How do you hold several different variables in one variable in scar

 

since that's probably confusing wording here's examples from other languages:

 

Python (suppose it would be a list):

list = ['1st Variable','2nd Variable','3rd Variable','4th Variable']

 

C++ (array or vector)

int array [4] = {1,2,3,4};

Edited by randomphobia
Link to comment
Share on other sites

Check out the wiki or tutorials. Its all right there. Tutorial section on forums.

 

[scar]

program New;

 

var

Arr1: array[1..5] of Integer; // only goes from 1 to 5 on array STATIC array

Arr2: array of Integer; // array of integer DYNAMIC ARRAY

Arr3: TIntArray; // Same thing as Arr2 same type DYNAMIC array

 

 

begin

Arr1[1] := 5;

Arr2 := [1,2,3];

Arr3 := [1];

end.

 

[/scar]

Link to comment
Share on other sites

In Pascal arrays are defined as:

MyVar: array of <datatype>;

The 1st item in the above array is MyVar[0]. If you wanted to specify the lower and upper bounds of the array:

MyVar: array [4..7] of <datatype>;

 

Freddy has predefined some datatypes for ease of coding. TIntArray - array of Integer, TStrArray - array of string, etc. So to take your 2nd example:

var
 MyVar: TIntArray;

begin
 MyVar := [1,2,3,4];

 // Or you could do this...
 SetLength(MyVar, 4);
 MyVar[0] = 1;
 MyVar[1] = 2;
 MyVar[2] = 3;
 MyVar[3] = 4;
end;

 

Edit: Ninja'd again.

Edited by Bixby Sayz
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
  • Create New...