Results 1 to 21 of 21

Thread: All About Inc and IncEx - NaumanAkhlaQ

  1. #1
    Join Date
    Mar 2007
    Posts
    4,810
    Mentioned
    3 Post(s)
    Quoted
    3 Post(s)

    Default All About Inc and IncEx - Naum

    All About Inc and IncEx


    Hello and welcome to my short tutorial about Inc and IncEx. As you may or may not know there are alot of uses for this. Mainly this is used as an alterative to variable adding and subtracting.


    Inc
    Inc is basically Var := Var + 1, this may seem framiliar to you - rack your brains for this. Yes you guessed this is used in progress reports e.g
    SCAR Code:
    Banked := Banked + 1;
    So how do we use it?
    Arguments for Inc are :
    PHP Code:
    procedure Inc(var X);
      
    Increases X with 1. 
    So its usage is basically Inc(Your Variable). For example instead of using Banked := Banked + 1; you can just do -
    SCAR Code:
    Inc(Banked)
    Simple, really? Well what if you want to add more than one to the variable?? Well read on...


    IncEx
    IncEx is basically the same as Inc as what it does is add or subtract from the variable. This is used when you want to add more than one onto a variable e.g

    SCAR Code:
    OresMined := OresMined + 27;
    So How de we use it?
    Arguments for IncEx are :
    PHP Code:
    procedure IncEx(var XNInteger);
      
    Increases X with N
    So its usage is basically IncEx(YourVariable, Howmuch you add to your var);. For example instead using OresMined := OresMined + 27; just do -
    SCAR Code:
    IncEx(OresMined, 27)
    Simple you see.

    Other examples
    Munk uses IncEx in his game to add to the score, but remeber you can also use inc like this :
    SCAR Code:
    For i := 0 to 26 Do
        Inc(Var);
    Also you may be able to minus the values e.g
    SCAR Code:
    IncEx(u, -34)

    Hope you all learned something today, Peace out.
    Last edited by Naum; 09-19-2012 at 12:17 PM.

  2. #2
    Join Date
    Dec 2006
    Location
    Banville
    Posts
    3,914
    Mentioned
    12 Post(s)
    Quoted
    98 Post(s)

    Default

    This is not really needed. I have never seen a thread asking about this.

    Most compilers/interpreters directly change I := I + 1; to the INC opcode, so you mostly won't want to worry.
    The jealous temper of mankind, ever more disposed to censure than
    to praise the work of others, has constantly made the pursuit of new
    methods and systems no less perilous than the search after unknown
    lands and seas.

  3. #3
    Join Date
    Dec 2006
    Location
    Sweden
    Posts
    10,812
    Mentioned
    3 Post(s)
    Quoted
    16 Post(s)

    Default

    EvilChicken! made this code R0B0t1. See how Inc(); > X := X + 1;
    SCAR Code:
    program FastTime;
    var x,y: integer;
    const Count = 1000000;
    begin
      ClearDebug;
      WriteLn('Please wait a few seconds...');
      X := GetSystemTime;
      for Y:= 0 to Count do
        Y := Y + 1;
      ClearDebug;
      WriteLn('Took '+IntToStr(GetSystemTime - X)+' ms to do '+Inttostr(Count)+' incs using Y := Y + 1;');
      X := GetSystemTime;
      for Y:= 0 to Count do
        Inc(Y);
      WriteLn('Took '+IntToStr(GetSystemTime - X)+' ms to do '+Inttostr(Count)+' incs using Inc(Y);');
      WriteLn('');
      WriteLn('Use Inc();!');
    end.
    I get
    Took 1141 ms to do 1000000 incs using Y := Y + 1;
    Took 984 ms to do 1000000 incs using Inc(Y);

    Use Inc();!
    Successfully executed
    It is not much, but it still shows how much better inc() is.

    Nice tut Naum


    Send SMS messages using Simba
    Please do not send me a PM asking for help; I will not be able to help you! Post in a relevant thread or make your own! And always remember to search first!

  4. #4
    Join Date
    Apr 2008
    Location
    Northwest england
    Posts
    1,179
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    for Y:= 0 to Count do
    Inc(Y);
    that is bad codeing erm and incex(u,-34)

    or you could do decEx(u,34) =]

    dod did you drag out that tuorial
    Blank!

  5. #5
    Join Date
    May 2007
    Location
    Ohio
    Posts
    2,296
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by Hy71194 View Post
    EvilChicken! made this code R0B0t1. See how Inc(); > X := X + 1;
    SCAR Code:
    program FastTime;
    var x,y: integer;
    const Count = 1000000;
    begin
      ClearDebug;
      WriteLn('Please wait a few seconds...');
      X := GetSystemTime;
      for Y:= 0 to Count do
        Y := Y + 1;
      ClearDebug;
      WriteLn('Took '+IntToStr(GetSystemTime - X)+' ms to do '+Inttostr(Count)+' incs using Y := Y + 1;');
      X := GetSystemTime;
      for Y:= 0 to Count do
        Inc(Y);
      WriteLn('Took '+IntToStr(GetSystemTime - X)+' ms to do '+Inttostr(Count)+' incs using Inc(Y);');
      WriteLn('');
      WriteLn('Use Inc();!');
    end.
    I get

    It is not much, but it still shows how much better inc() is.

    Nice tut Naum
    o_O
    Took 782 ms to do 1000000 incs using Y := Y + 1;
    Took 609 ms to do 1000000 incs using Inc(Y);

    Use Inc();!

  6. #6
    Join Date
    Feb 2006
    Location
    Amsterdam
    Posts
    13,691
    Mentioned
    146 Post(s)
    Quoted
    130 Post(s)

    Default

    Quote Originally Posted by Hy71194 View Post
    EvilChicken! made this code R0B0t1. See how Inc(); > X := X + 1;
    SCAR Code:
    program FastTime;
    var x,y: integer;
    const Count = 1000000;
    begin
      ClearDebug;
      WriteLn('Please wait a few seconds...');
      X := GetSystemTime;
      for Y:= 0 to Count do
        Y := Y + 1;
      ClearDebug;
      WriteLn('Took '+IntToStr(GetSystemTime - X)+' ms to do '+Inttostr(Count)+' incs using Y := Y + 1;');
      X := GetSystemTime;
      for Y:= 0 to Count do
        Inc(Y);
      WriteLn('Took '+IntToStr(GetSystemTime - X)+' ms to do '+Inttostr(Count)+' incs using Inc(Y);');
      WriteLn('');
      WriteLn('Use Inc();!');
    end.
    I get

    It is not much, but it still shows how much better inc() is.

    Nice tut Naum
    Meh. This is SCAR. In any other language Inc() would never be faster.



    The best way to contact me is by email, which you can find on my website: http://wizzup.org
    I also get email notifications of private messages, though.

    Simba (on Twitter | Group on Villavu | Website | Stable/Unstable releases
    Documentation | Source | Simba Bug Tracker on Github and Villavu )


    My (Blog | Website)

  7. #7
    Join Date
    May 2008
    Location
    Here :p
    Posts
    194
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    quite a people still use
    I := I + 1;
    but
    inc(I);
    is faster easyer ad just basacly better nice tut (boy did u make it a hell of alot longer than i though i was exspecting 5 lines XD)

  8. #8
    Join Date
    Mar 2007
    Posts
    4,810
    Mentioned
    3 Post(s)
    Quoted
    3 Post(s)

    Default

    Just made it. I find it more efficient, a procedure that does it for you

    But mind you, Inc probeblly looks like this:

    SCAR Code:
    Procedure Inc(Var X);
    Begin
      X := X + 1;
    end;



    E: @ Waddo - If I find anything that people might need to know I make a tutorial about it.

  9. #9
    Join Date
    Jan 2008
    Location
    California, US
    Posts
    2,765
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    You can also use this IncEx procedure .

    SCAR Code:
    procedure IncEx(var i : integer; var TheModifier : integer; Add : boolean);
    begin
      if Add then
      i := i + TheModifier;
      if not Add then
      i := i - TheModifier;
    end;

    i: The variable you want to modify.
    TheModifier: The amount you want to modify it by.
    Add: True/False True to add to i. False to subtract.

  10. #10
    Join Date
    Dec 2006
    Location
    Program TEXAS home of AUTOERS
    Posts
    7,934
    Mentioned
    26 Post(s)
    Quoted
    237 Post(s)

    Default

    gj, i used it once or twice , but not really needed can be subsitute with numerous other stuff.

  11. #11
    Join Date
    Feb 2006
    Location
    Helsinki, Finland
    Posts
    1,395
    Mentioned
    30 Post(s)
    Quoted
    107 Post(s)

    Default

    Quote Originally Posted by Wizzup? View Post
    Meh. This is SCAR. In any other language Inc() would never be faster.
    What does it matter though? We are using SCAR. So, if Inc(var) is faster in SCAR than var:= var + 1, then we definitely should stick with that.. I don't care about other languages, not at least while I am scripting with SCAR...

    Very nice little tutorial, Nauman!

  12. #12
    Join Date
    Mar 2007
    Posts
    4,810
    Mentioned
    3 Post(s)
    Quoted
    3 Post(s)

    Default

    Thanks, for the post.
    Also could inc be like this :

    SCAR Code:
    Procedure Inc(var x : Integer);
    Begin
      Inc(x);
    end;


    Simpler

    SCAR Code:
    procedure IncEx(var i : integer; var TheModifier : integer; Add : boolean);
    begin
      if Add then
      i := i + TheModifier;
      if not Add then
      i := i - TheModifier;
    end;

    to

    SCAR Code:
    procedure IncEx(var i : integer; var TheModifier : integer; Add : boolean);
    begin
      if Add then
        IncEx(i, TheModifier)
      else
        DecEx(i, TheModifier);
    end;

  13. #13
    Join Date
    Jan 2008
    Location
    Ontario, Canada
    Posts
    7,805
    Mentioned
    5 Post(s)
    Quoted
    3 Post(s)

    Default

    By the way, IncEx is actually slower than doing Variable := Variable + Number;.

    Just so you know.

    Also, as others have mentioned, maybe add Dec(x) and DecEx(x, count)

    Good tut though.
    Writing an SRL Member Application | [Updated] Pascal Scripting Statements
    My GitHub

    Progress Report:
    13:46 <@BenLand100> <SourceCode> @BenLand100: what you have just said shows you 
                        have serious physchological problems
    13:46 <@BenLand100> HE GETS IT!
    13:46 <@BenLand100> HE FINALLY GETS IT!!!!1

  14. #14
    Join Date
    Feb 2006
    Location
    Amsterdam
    Posts
    13,691
    Mentioned
    146 Post(s)
    Quoted
    130 Post(s)

    Default

    Quote Originally Posted by NaumanAkhlaQ View Post
    Thanks, for the post.
    Also could inc be like this :

    SCAR Code:
    Procedure Inc(var x : Integer);
    Begin
      Inc(x);
    end;


    Simpler

    SCAR Code:
    procedure IncEx(var i : integer; var TheModifier : integer; Add : boolean);
    begin
      if Add then
      i := i + TheModifier;
      if not Add then
      i := i - TheModifier;
    end;

    to

    SCAR Code:
    procedure IncEx(var i : integer; var TheModifier : integer; Add : boolean);
    begin
      if Add then
        IncEx(i, TheModifier)
      else
        DecEx(i, TheModifier);
    end;
    If you remake Inc() in SCAR is will be slower than just doing + someNumber.
    The only part that actually makes Inc() faster is because it is not compiled by SCAR.



    The best way to contact me is by email, which you can find on my website: http://wizzup.org
    I also get email notifications of private messages, though.

    Simba (on Twitter | Group on Villavu | Website | Stable/Unstable releases
    Documentation | Source | Simba Bug Tracker on Github and Villavu )


    My (Blog | Website)

  15. #15
    Join Date
    Sep 2006
    Posts
    6,089
    Mentioned
    77 Post(s)
    Quoted
    43 Post(s)

    Default

    Did you know that you can also Inc/Dec booleans?

    Quote Originally Posted by NaumanAkhlaQ View Post
    Thanks, for the post.
    Also could inc be like this :

    SCAR Code:
    Procedure Inc(var x : Integer);
    Begin
      Inc(x);
    end;


    Simpler

    SCAR Code:
    procedure IncEx(var i : integer; var TheModifier : integer; Add : boolean);
    begin
      if Add then
      i := i + TheModifier;
      if not Add then
      i := i - TheModifier;
    end;

    to

    SCAR Code:
    procedure IncEx(var i : integer; var TheModifier : integer; Add : boolean);
    begin
      if Add then
        IncEx(i, TheModifier)
      else
        DecEx(i, TheModifier);
    end;
    Both your Inc and IncEx would become a potential infinite loop =\
    Hup Holland Hup!

  16. #16
    Join Date
    Apr 2007
    Location
    Here
    Posts
    109
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    [QUOTE=nielsie95;466441]Did you know that you can also Inc/Dec booleans?

    I'm curious, how do you inc a boolean? And what is the use, if boolean is only true/false what would be the point? Unless it is like boolean[i]

  17. #17
    Join Date
    Jun 2006
    Posts
    3,861
    Mentioned
    3 Post(s)
    Quoted
    0 Post(s)

    Default

    [QUOTE=welcome;470241]
    Quote Originally Posted by nielsie95 View Post
    Did you know that you can also Inc/Dec booleans?

    I'm curious, how do you inc a boolean? And what is the use, if boolean is only true/false what would be the point? Unless it is like boolean[i]
    A boolean is one bit. 0 or 1. So if it is true, it is really just the number 1. False would be 0. So all it would be doing is adding or subtracting from 0 or 1.

    And Nauman, I'm pretty sure that inc looks something like this:
    SCAR Code:
    procedure Inc(var I);
    asm
      mov eax, [I]
      inc eax
      mov [I], eax
    end;

    EDIT: Seems I'm wrong. A boolean is a byte.. =/

  18. #18
    Join Date
    Sep 2006
    Posts
    6,089
    Mentioned
    77 Post(s)
    Quoted
    43 Post(s)

    Default

    I think it's an enumeration:

    SCAR Code:
    program New;
    type
      THello = (Hi, You, There);
    var
      Hello: THello;
    begin
      Hello := Hi;
      Inc(Hello);
      case Hello of
        Hi: WriteLn('Hi');
        You: WriteLn('You');
        There: WriteLn('There');
      end;
    end.
    Hup Holland Hup!

  19. #19
    Join Date
    Jun 2006
    Posts
    3,861
    Mentioned
    3 Post(s)
    Quoted
    0 Post(s)

    Default

    I don't think so, because when Hello goes past a value of 2, the case stops recognizing it, whereas if a boolean goes past the value of 1, it still recognizes that it is "true".

  20. #20
    Join Date
    Sep 2006
    Posts
    6,089
    Mentioned
    77 Post(s)
    Quoted
    43 Post(s)

    Default

    BoolToStr recognizes as true, but take a look at this:

    SCAR Code:
    program New;
    type
      THello = (Hi, You, There);
    var
      Hello: THello;
      b: Boolean;
    begin
      Hello := You;
      Inc(Hello);
      case Hello of
        Hi: WriteLn('Hello = Hi');
        You: WriteLn('Hello = You');
        There: WriteLn('Hello = There');
      end;
      WriteLn('Hello = '+IntToStr(Variant(Hello)));
      WriteLn('BoolToStr(Hello): '+BoolToStr(Variant(Hello)));
      Inc(b);
      Inc(b);
      WriteLn('b = '+IntToStr(Variant(b)));
      WriteLn('b = true: '+BoolToStr(b = true));
    end.
    Hup Holland Hup!

  21. #21
    Join Date
    Jun 2006
    Posts
    3,861
    Mentioned
    3 Post(s)
    Quoted
    0 Post(s)

    Default

    Oh, somehow I tested it wrong. I had a case statement set up, but I did something wrong (I guess I forgot to put another inc ).

    Fine, you win, I lose.

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
  •