SRL Archive - OSR Intermediate Scripting Tutorials

Defines


Shuttleu

2011-12-27 05:58:22

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:

{$DEFINE SOMETHING}

You can then use it to testif it is defined

{$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


{$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


{$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


{$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
{$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

BraK

2011-12-27 06:07:44

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.

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

Shuttleu

2011-12-27 06:08:20

From: BraK
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.


now adding them

~shut

Kyle Undefined

2011-12-27 09:48:43

Nice tut! Should help people convert their scripts over to SRL5. Perfect timing!

Sabzi

2011-12-27 10:03:41

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

Brandon

2011-12-27 10:08:10

Can you do something like:

Define X Repeat
Define Y Until(!condition)

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

Shuttleu

2011-12-27 17:01:48

From: Sabzi
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
From: ggzz
Can you do something like:

Define X Repeat
Define Y Until(!condition)

That way you can do sometjing like.
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