Results 1 to 12 of 12

Thread: Declaring constant array of Integers

  1. #1
    Join Date
    Oct 2011
    Posts
    207
    Mentioned
    1 Post(s)
    Quoted
    20 Post(s)

    Default Declaring constant array of Integers

    How do I declare constant array of integers?

    I tried:

    Simba Code:
    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....?

  2. #2
    Join Date
    Feb 2006
    Posts
    3,044
    Mentioned
    4 Post(s)
    Quoted
    21 Post(s)

    Default

    Simba Code:
    program new;

    var
      TIA :TIntegerArray;

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


    ~Home

  3. #3
    Join Date
    Mar 2012
    Location
    Canada
    Posts
    870
    Mentioned
    1 Post(s)
    Quoted
    5 Post(s)

    Default

    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.
    My scripts:
    Advanced Barb Agility Course(outdated), MonkeyThieverV0.11, MahoganyTableV0.4(outdated)
    Questions? I bet that for 98% of those, you'll find answer HERE

  4. #4
    Join Date
    Dec 2007
    Posts
    2,112
    Mentioned
    71 Post(s)
    Quoted
    580 Post(s)

    Default


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

    lol just tried it, it actually doesnt let you, learn something new everyday -.-, ignore this post
    Last edited by Kasi; 08-22-2012 at 06:54 PM.

  5. #5
    Join Date
    Sep 2008
    Location
    Not here.
    Posts
    5,422
    Mentioned
    13 Post(s)
    Quoted
    242 Post(s)

    Default

    Lape can do it
    Simba Code:
    program default;

    const
      i = [1,1];

    begin
      writeln(tostr(i));
    end.

  6. #6
    Join Date
    Oct 2011
    Posts
    207
    Mentioned
    1 Post(s)
    Quoted
    20 Post(s)

    Default

    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?

  7. #7
    Join Date
    Jan 2008
    Location
    C:\
    Posts
    1,483
    Mentioned
    2 Post(s)
    Quoted
    2 Post(s)

    Default

    Quote Originally Posted by djborec View Post
    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:

    Simba Code:
    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;

  8. #8
    Join Date
    Oct 2011
    Posts
    207
    Mentioned
    1 Post(s)
    Quoted
    20 Post(s)

    Default

    Runaway thanks,

    so there is nothing as dynamic array in Pascal script?

  9. #9
    Join Date
    Jan 2009
    Location
    Turlock/LA, California
    Posts
    1,494
    Mentioned
    3 Post(s)
    Quoted
    66 Post(s)

    Default

    Quote Originally Posted by djborec View Post
    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.

  10. #10
    Join Date
    Oct 2006
    Location
    Netherlands
    Posts
    3,285
    Mentioned
    105 Post(s)
    Quoted
    494 Post(s)

    Default

    Quote Originally Posted by x[Warrior]x3500 View Post
    nope, but in Lape we have access to pointers/ref. so we can create linked lists if we wanted.
    When lape is option anyway...

    Simba Code:
    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.
    Working on: Tithe Farmer

  11. #11
    Join Date
    Jan 2012
    Posts
    2,568
    Mentioned
    35 Post(s)
    Quoted
    356 Post(s)

    Default

    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.

  12. #12
    Join Date
    Oct 2007
    Location
    #srl
    Posts
    6,102
    Mentioned
    39 Post(s)
    Quoted
    62 Post(s)

    Default

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

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •