Results 1 to 7 of 7

Thread: Variable i

  1. #1
    Join Date
    Oct 2006
    Posts
    517
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default Variable i

    I've been studying Fakawi's Goblin Scheduler, and on it...
    SCAR Code:
    procedure PlayerStats;

    var Active: string;
    var i, temp: Integer;
    begin
      if Players[CurrentPlayer].Active=True then
        Active:='True'
       else
        Active:='False';
      WriteLn ('<~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~>');
      Writeln ('  Name         : '+ Players[CurrentPlayer].Name);
      Writeln ('  Number       : '+inttostr(CurrentPlayer));
      Writeln ('  Active       : '+ Active);
      if ( Players[CurrentPlayer].Worked > 0 ) then
        Writeln ('  Worked       : '+ inttostr(Players[CurrentPlayer].Worked));
      Writeln ('  Location     : '+ Players[CurrentPlayer].loc);
      Temp:=(GetSystemTime div 1000);
      Temp := Temp - StartTime;
      if ( playtime < temp ) then
      Writeln ('  Time Left    : '+ IntToStr ( Temp - PlayTime / 60 ) + ' min[s].');
      WriteLn ('<~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~>');

      for I := 0 to HowManyPlayers - 1 do
      begin
        if Players[i].Active=True then Active:='T' else Active:='F';
        WriteLn ( ' ' + Inttostr ( I) + ' : ' + Players[i].Name + ' = ' + Active
        +'. - Lvl : '
        +' '+inttostr(Players[i].level[1])
        +' '+inttostr(Players[i].level[2])
        +' '+inttostr(Players[i].level[3])+
        +' '+inttostr(Players[i].level[5])+
        +' '+inttostr(Players[i].level[8])+'. '
        +'W : '+IntToStr(Players[i].Worked)+' min. '
        +'K : '+ IntToStr(Players[i].Killed)+' Goblins. '
        +'L: '+Players[i].loc);
      end

    See how i is declared and used in that procedure, and in this one:
    SCAR Code:
    procedure FTWaitD ( Time : Integer );
    var T, I : integer;
    begin
      try

        T := (Time div 1000)+1;
        for I := 1 to T do
        begin
          Wait ( 250 );
          FindTalk;
        end

      except

        begin
          Wait ( Time );
          FindTalk;
        end;

      end;

    Can you use i multiple times after its been ended?

    Also, btw, whats the "div" mean in the 2nd ScarScript?

  2. #2
    Join Date
    Sep 2006
    Posts
    916
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    divided i think.

  3. #3
    Join Date
    Oct 2006
    Posts
    517
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

  4. #4
    Join Date
    Mar 2006
    Location
    USA
    Posts
    948
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    "div" or "/" are the SCAR equivalents to division.

    The Variable "i" like any variable can be declared once globally and once within each procedure or function

  5. #5
    Join Date
    Oct 2006
    Posts
    517
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

  6. #6
    Join Date
    Sep 2006
    Posts
    5,219
    Mentioned
    4 Post(s)
    Quoted
    1 Post(s)

    Default

    When i(or any variable) is declared in a procedure or function like

    procedure blahblah;
    var i:integer;
    begin
    repeat
    writeln('stuff');
    i:=i+1;
    until i=4;
    end;

    i is 'loaded' at the begin, and 'forgotten' at the end, every time the procedure is called. Every time the procedure is called, booleans start as false, integers as 0, and strings as ''.

    Code:
    program New;
    {comment line 6 and leave line 8 uncommented and you should get
    123123. comment line 8 and uncomment line 6 and you should get
    123456, because global i is 'remembered'}
                           //  comment
    //var i:integer;       //  this line
    procedure countto3;    //  or
    var i:integer;         //  that line
    begin
    i:=i+1;
    writeln(inttostr(i));
    i:=i+1;
    writeln(inttostr(i));
    i:=i+1;
    writeln(inttostr(i));
    
    end;
    
    //////EDIT FORGOT THIS PART LOL
    
    begin 
    countto3;
    countto3;
    end.
    This also means that multiple procedures can use a variable locally without affecting each other. This is why SRL uses local variables more than globals when possible.

  7. #7
    Join Date
    Oct 2006
    Posts
    517
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Help with storing variable
    By Drew_Dawg in forum OSR Help
    Replies: 1
    Last Post: 02-02-2008, 11:54 AM
  2. UseSandwichSolver variable...
    By orion pax in forum OSR Help
    Replies: 2
    Last Post: 10-22-2007, 08:57 PM
  3. Is there any variable like...?
    By dritar in forum OSR Help
    Replies: 2
    Last Post: 10-05-2007, 06:07 PM
  4. Increasing a variable
    By Its Miller Time in forum OSR Help
    Replies: 12
    Last Post: 06-06-2007, 06:43 PM

Posting Permissions

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