Results 1 to 7 of 7

Thread: Defines

  1. #1
    Join Date
    Aug 2007
    Location
    in a random little world
    Posts
    5,778
    Mentioned
    0 Post(s)
    Quoted
    7 Post(s)

    Default Defines

    Defines


    Defines are a way of setting code to be included or not at compile-time

    For example, you might want a bit of code to be compiled if something has been defined, however if the define does not exist then the piece of code will not be included in the compiling.

    you define something like so:
    Simba Code:
    {$DEFINE SOMETHING}

    You can then use it to testif it is defined
    Simba Code:
    {$IFDEF SOMETHING}
      //Some Code Here
    {$ENDIF}

    now the code between the two tags above will only be compiled if it has been defined

    This is particularly useful if you have several files and you want to make sure the person has all the files or if you want to debug some code

    This is what is used in order for smart to work easily in your scripts, If SMART has been defined then SRL will automatically include everything you need.

    There are also built in defines which allow you to include certain code if the end user is running a certain version of simba

    Simba Code:
    {$IFDEF SIMBA980}
      //Some stuff
    {$ENDIF}

    The above will only be run if the user is running Simba rev. 980, this is particularly useful if you there is a bug that can be fixed by some code

    There is also one for checking whether something has not been defined

    Simba Code:
    {$IFNDEF SIMBA980}
      //Some stuff
    {$ENDIF}

    The above will only be run if the user is not running Simba rev. 980

    And finally there is one more directive, else

    Simba Code:
    {$IFDEF SIMBA980}
      //Some stuff
    {$ELSE}
      //Some other stuff
    {$ENDIF}

    This way if you want one piece of code to be used if something is defined but another piece if it is not then this can be used

    They can also be used to make scripts ready for future updates
    for example, SRL4 uses the.scar extension, but SRL5 uses the.simba extension, by using defines we can change which file it uses
    Simba Code:
    {$IFDEF SRL5}
      {$i SRL/SRL.simba}
      {$i SRL/SRL/MISC/Debug.simba}
    {$ELSE}
      {$i SRL/SRL.scar}
      {$i SRL/SRL/MISC/Debug.scar}
    {$ENDIF}

    Here, if we define SRL5 then it will include the SRL5 files, however if we do not then it will define the SRL4 files
    This can be used in other parts of the code, allowing the script to be used by both SRL4 and SRL5

    This is only a rough guide and i will polish it off a bit more later on

    ~shut
    Last edited by Shuttleu; 12-27-2011 at 10:06 PM.

  2. #2
    Join Date
    Mar 2006
    Location
    Behind you
    Posts
    3,193
    Mentioned
    61 Post(s)
    Quoted
    63 Post(s)

    Default

    Add the SRL4 and SRL5 Defines.

    As SRL4 uses .scar and SRL5 uses .simba you need to define them if you are going to have it compatible for both.

    Simba Code:
    {$IFDEF SRL5}
      {$i SRL/SRL.simba}
      {$i SRL/SRL/MISC/Debug.simba}
    {$ELSE}
      {$i SRL/SRL.scar}
      {$i SRL/SRL/MISC/Debug.scar}
    {$ENDIF}

    "Sometimes User's don't need the Answer spelled out with Code. Sometimes all they need is guidance and explanation of the logic to get where they are going."

  3. #3
    Join Date
    Aug 2007
    Location
    in a random little world
    Posts
    5,778
    Mentioned
    0 Post(s)
    Quoted
    7 Post(s)

  4. #4
    Join Date
    Oct 2008
    Location
    C:\Simba\Includes\
    Posts
    7,566
    Mentioned
    19 Post(s)
    Quoted
    180 Post(s)

    Default

    Nice tut! Should help people convert their scripts over to SRL5. Perfect timing!
    Away for awhile, life is keeping me busy. | Want to get my attention in a thread? @Kyle Undefined; me.
    { MSI Phoenix || SRL Stats Sigs || Paste || Scripts || Quotes || Graphics }

    When posting a bug, please post debug! Help us, help you!

    I would love to change the world, but they won't give me the source code. || To be the best, you've got to beat the rest. || Logic never changes, just the syntax.
    If you PM me with a stupid question or one listed in FAQ, or about a script that is not mine, I will NOT respond.


    SRL is a Library of routines made by the SRL community written for the Program Simba. We produce Scripts for the game Runescape.


  5. #5
    Join Date
    Feb 2009
    Location
    Hungary (GMT + 1)
    Posts
    1,774
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    There's also IFNDEF, might want to mention that too if we are at it.
    Sorry if I just didn't see it.

  6. #6
    Join Date
    Feb 2011
    Location
    The Future.
    Posts
    5,600
    Mentioned
    396 Post(s)
    Quoted
    1598 Post(s)

    Default

    Can you do something like:

    Define X Repeat
    Define Y Until(!condition)

    That way you can do sometjing like.
    Code:
    X
                    silly example but can it be done?
    Y(i > 0);
    I am Ggzz..
    Hackintosher

  7. #7
    Join Date
    Aug 2007
    Location
    in a random little world
    Posts
    5,778
    Mentioned
    0 Post(s)
    Quoted
    7 Post(s)

    Default

    Quote Originally Posted by Sabzi View Post
    There's also IFNDEF, might want to mention that too if we are at it.
    Sorry if I just didn't see it.
    ah, yes, i completely forgot
    Quote Originally Posted by ggzz View Post
    Can you do something like:

    Define X Repeat
    Define Y Until(!condition)

    That way you can do sometjing like.
    Code:
    X
                    silly example but can it be done?
    Y(i > 0);
    unfortunately no

    unlike C++ and other languages, Defines in Pascal are either "True" (defined) or "False" (undefined)

    ~shut

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
  •