Results 1 to 11 of 11

Thread: Array

  1. #1
    Join Date
    Apr 2007
    Location
    Colchester, UK
    Posts
    1,220
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default Array

    Hi Guys/Girls,

    i am wondering if i can have an active array, by active array i mean constantly adding to it while a script is running?
    i think its possible but i am not sure how to do it.

    i am wanting to store names in a array, that i will later go through in my script.

    thanks for any help

  2. #2
    Join Date
    Dec 2006
    Location
    Sydney, New South Wales, Australia
    Posts
    4,603
    Mentioned
    15 Post(s)
    Quoted
    42 Post(s)

    Default

    Yep, e.g:
    SCAR Code:
    var
      hl: Integer;
      arr: array of Integer;

    begin
      repeat
        SetLength(arr, Length(arr) + 1);
        arr[hl] := hl;
        Inc(hl);
      Until(hl >= 42);
    end.
    You may contact me with any concerns you have.
    Are you a victim of harassment? Please notify me or any other staff member.

    | SRL Community Rules | SRL Live Help & Chat | Setting up Simba | F.A.Q's |

  3. #3
    Join Date
    Jun 2007
    Location
    Wednesday
    Posts
    2,446
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default

    Dynamic arrays are what you are looking for.
    SCAR Code:
    var
      myArr: array of string;
      i: Integer;

    begin
      SetLength(myArr, Length(myArr) + 1); // Give it an extra index
      myArr[High(myArr)] := 'dave'; // Give it a value
      // However, all these Length and High calls are annoying, so...
      i := Length(myArr); // Get the length
      SetLength(myArr, i + 1); // Make it one longer
      myArr[i] := 'dave'; // Give it a value
    end.

    Hope that helps, if not then just say

    Edit: Silly Dan's the Man thought he ninja'd me, but more informative post is more informative!
    By reading this signature you agree that mixster is superior to you in each and every way except the bad ways but including the really bad ways.

  4. #4
    Join Date
    Apr 2007
    Location
    Colchester, UK
    Posts
    1,220
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    thanks guys, might not actually end up using it in my script, but its still good practice knowing about it.

    Edit: Is it possible to have an array of arrays?
    Last edited by Bobzilla69; 09-04-2009 at 09:44 PM.

  5. #5
    Join Date
    Dec 2006
    Location
    Sydney, New South Wales, Australia
    Posts
    4,603
    Mentioned
    15 Post(s)
    Quoted
    42 Post(s)

    Default

    Quote Originally Posted by bobzilla69 View Post
    thanks guys, might not actually end up using it in my script, but its still good practice knowing about it.

    Edit: Is it possible to have an array of arrays?
    Yep, they're known as Two-Dimensional Arrays. If you want array of array of array on Integer;, that is known as a three dimensional array - etc etc

    It can go on and on and on (as long as SCAR doesn't crash, forget how many causes it too. But it's like over 20 or something..):
    SCAR Code:
    array of array of array of array of array of array of Integer;
    You may contact me with any concerns you have.
    Are you a victim of harassment? Please notify me or any other staff member.

    | SRL Community Rules | SRL Live Help & Chat | Setting up Simba | F.A.Q's |

  6. #6
    Join Date
    Apr 2007
    Location
    Colchester, UK
    Posts
    1,220
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    ok thanks Dan.

    i have another problem now.

    i have made the script below to check two arrays for text thats in the arrays.

    however i can only get it to load the first array. what am i doing wrong?

    SCAR Code:
    program New;
    {.include SRL\SRL.scar}
    var
    arrayloop:integer;
    arrayload:tstringarray;
    NoMoreArrays:Boolean;

    Function LoadArray(arrayloop:integer):boolean;
    begin
      if arrayloop = 1 then
      begin
        writeln('array bigger than 1   '+inttostr(arrayloop));
        NoMoreArrays:= True;
        Exit;
      end;
      case arrayloop of
        0:
        begin
          arrayload:= ['dave', 'dom'];  
          writeln('array 0 loaded');
        end;
        1:
        begin
          arrayload:= ['jane', 'jess'];
          writeln('array 1 loaded');
        end;
      end;

    end;

    procedure test;
    var
    i:integer;
    PlayerCheck1, Message1:String;
    ChatFound:boolean;
    begin
      PlayerCheck1:= Lowercase(GetChatBoxText(8, clMessage));  //gets last message sender
      Message1:= Lowercase(GetChatBoxText(8, clChat));  //gets last message sender
      if PlayerCheck1 = '' then Exit;
      for i:=0 to high(arrayload)do //starts at 0 and goes to array length
      begin
        if(Pos(arrayload[i], Message1) > 0 )then
        begin
          ChatFound:= True;
        end else
        ChatFound:= False;
        writeln('chat not found');
      end;
    end;



    begin
    arrayloop:=0;
    repeat
      LoadArray(arrayloop);
      test;
      arrayloop:= + 1;
    until(NoMoreArrays = True)
    end.

  7. #7
    Join Date
    May 2007
    Location
    England
    Posts
    4,140
    Mentioned
    11 Post(s)
    Quoted
    266 Post(s)

    Default

    Quote Originally Posted by bobzilla69 View Post
    ok thanks Dan.

    i have another problem now.

    i have made the script below to check two arrays for text thats in the arrays.

    however i can only get it to load the first array. what am i doing wrong?

    Code:
    program New;
    {.include SRL\SRL.scar}
    var
    arrayloop:integer;
    arrayload:tstringarray;
    NoMoreArrays:Boolean;

    Function LoadArray(arrayloop:integer):boolean;
    begin
    if arrayloop = 1 then
    begin
    writeln('array bigger than 1 '+inttostr(arrayloop));
    NoMoreArrays:= True;
    Exit;
    end;
    case arrayloop of
    0:
    begin
    arrayload:= ['dave', 'dom'];
    writeln('array 0 loaded');
    end;
    1:
    begin
    arrayload:= ['jane', 'jess'];
    writeln('array 1 loaded');
    end;
    end;

    end;

    procedure test;
    var
    i:integer;
    PlayerCheck1, Message1:String;
    ChatFound:boolean;
    begin
    PlayerCheck1:= Lowercase(GetChatBoxText(8, clMessage)); //gets last message sender
    Message1:= Lowercase(GetChatBoxText(8, clChat)); //gets last message sender
    if PlayerCheck1 = '' then Exit;
    for i:=0 to high(arrayload)do //starts at 0 and goes to array length
    begin
    if(Pos(arrayload[i], Message1) > 0 )then
    begin
    ChatFound:= True;
    end else
    ChatFound:= False;
    writeln('chat not found');
    end;
    end;



    begin
    arrayloop:=0;
    repeat
    LoadArray(arrayloop);
    test;
    arrayloop:= + 1;
    until(NoMoreArrays = True)
    end.
    Change
    SCAR Code:
    if arrayloop = 1
    To
    SCAR Code:
    if arrayloop > 1
    <3

    Quote Originally Posted by Eminem
    I don't care if you're black, white, straight, bisexual, gay, lesbian, short, tall, fat, skinny, rich or poor. If you're nice to me, I'll be nice to you. Simple as that.

  8. #8
    Join Date
    Apr 2007
    Location
    Colchester, UK
    Posts
    1,220
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    i have tried that, doesnt work.

    the debug i have
    SCAR Code:
    writeln('array bigger than 1   '+inttostr(arrayloop));
    it never triggers which means it never reaches any higher than 1
    Last edited by Bobzilla69; 09-05-2009 at 12:45 AM.

  9. #9
    Join Date
    May 2007
    Location
    England
    Posts
    4,140
    Mentioned
    11 Post(s)
    Quoted
    266 Post(s)

    Default

    Going to re-write the whole thing now. I'll edit my post when I'm done.

    EDIT:

    SCAR Code:
    program ChatTest;
    {.include SRL\SRL.scar}

    var
      ArrayLoop : Integer;
      ArrayLoad : TStringArray;
      NoMoreArrays : Boolean;

    function LoadArray(ArrLoop : Integer) : Boolean;
    begin
      if ArrLoop > 1 then
      begin
        WriteLn('ArrLoop is to be either 0 or 1');
        NoMoreArrays:= True;
        Exit;
      end;
      case ArrLoop of
        0: begin
             ArrayLoad:= ['dave', 'dom'];
             writeln('Array 0 loaded');
           end;
        1: begin
             ArrayLoad:= ['jane', 'jess'];
             WriteLn('Array 1 loaded');
           end;
      end;
    end;

    procedure Test;
    var
      I : Integer;
      PCheck, Msg : string;
      ChatFound : Boolean;
     
    begin
      PCheck:= Lowercase(GetChatBoxText(8, clMessage));
      Msg:= Lowercase(GetChatBoxText(8, clChat));
      if PCheck = '' then
        Exit;
      for I:= 0 to High(ArrayLoad)do
      begin
        if(Pos(ArrayLoad[I], Msg) > 0 )then
          ChatFound:= True;
        else
          WriteLn('Chat not found');
      end;
    end;

    begin
      SetupSRL;
      ArrayLoop:= 0;
      repeat
        LoadArray(ArrayLoop);
        Test;
        Inc(ArrayLoop);
      until(NoMoreArrays)
    end.

    That should work.
    Last edited by Rich; 09-05-2009 at 12:51 AM.
    <3

    Quote Originally Posted by Eminem
    I don't care if you're black, white, straight, bisexual, gay, lesbian, short, tall, fat, skinny, rich or poor. If you're nice to me, I'll be nice to you. Simple as that.

  10. #10
    Join Date
    Apr 2007
    Location
    Colchester, UK
    Posts
    1,220
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Line 41: [Error] (19838:1): Identifier expected in script C:\Program Files\SCAR 3.21\Scripts\rich loop.scar

    its the els its pointing at but must be something els, tried to fix it but i dont understand.

    can you also attach it as script if it aint to much of a problem, never copies right allways one line of code

    Edit: Dont worry fixed it, working great thanks R1ch. it loops through last array twice is the only thing i noticed

    Edit:fixed looping by adding
    SCAR Code:
    if NoMoreArrays = True then Exit;
    in the test procedure

    Finishing code is
    SCAR Code:
    program ChatTest;
    {.include SRL\SRL.scar}
    var
      ArrayLoop : Integer;
      ArrayLoad : TStringArray;
      NoMoreArrays : Boolean;
    function LoadArray(ArrayLoop : Integer) : Boolean;
    begin
      if ArrayLoop > 1 then
      begin
        WriteLn('ArrayLoop is to be either 0 or 1');
        NoMoreArrays:= True;
        Exit;
      end;
      case ArrayLoop of
      0: begin
           ArrayLoad:= ['dave', 'dom'];
           writeln('Array 0 loaded');
         end;
      1: begin
           ArrayLoad:= ['jane', 'jess', 'gem'];
           WriteLn('Array 1 loaded');
         end;
      end;
    end;

    procedure Test;
    var
      I : Integer;
      PCheck, Msg : string;
      ChatFound : Boolean;
    begin
      PCheck:= Lowercase(GetChatBoxText(8, clMessage));
      Msg:= Lowercase(GetChatBoxText(8, clChat));
      if PCheck = '' then Exit;
      if NoMoreArrays = True then Exit;
      for I:= 0 to High(ArrayLoad)do
      begin
        if(Pos(ArrayLoad[i], Msg) > 0 )then
        begin
          ChatFound:= True;
        end else
        WriteLn('Chat not found');
      end;
    end;

    begin
      SetupSRL;
      ArrayLoop:= 0;
      repeat
        LoadArray(ArrayLoop);
        Test;
        Inc(ArrayLoop);
      until(NoMoreArrays)
    end.
    Last edited by Bobzilla69; 09-05-2009 at 01:17 AM.

  11. #11
    Join Date
    May 2007
    Location
    England
    Posts
    4,140
    Mentioned
    11 Post(s)
    Quoted
    266 Post(s)

    Default

    No problem. I'm glad I could help. If you have any more problems, PM me and I'll get back to you ASAP.
    <3

    Quote Originally Posted by Eminem
    I don't care if you're black, white, straight, bisexual, gay, lesbian, short, tall, fat, skinny, rich or poor. If you're nice to me, I'll be nice to you. Simple as that.

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
  •