SRL Archive - OSR Advanced Scripting Tutorials

using {$Define }


Magiic

2008-12-08 14:39:28

Using {$Define }


{$Define } although a very simple feature isn't really included in many scripts i've noticed, but although unknown it is extremely useful, for things such as SMART.

For example, instead of having to either have two scripts, one smart, one not you could simply use {$Define}


{$Define SMART}

Well, what this basically does is define the thing SMART so that if you use

{$IfDef SMART}
{.include srl/srl/misc/smart.scar}
{$EndIf}

it would include Smart as it has been defined (hence IfDef) if it were commented out however it wouldn't include smart as you wouldn't have defined it.

This also works in the main loop so you can use it there like so
{$IfDef SMART}
SmartSetupEx(world, false, true, false);
SetTargetDC(SmartGetDC);
{$EndIf}
so yeah that's the end of my small tut, post questions if you have any please :)

you can also use
{$UnDef} 
which does exactly what it says it removes something you have previously defined
{$IfNDef}
which will do something if something isn't defined, in other words
the opposite of {$IfDef}

Edit:apparently ScarScript needs to be updated for this, it should be black.

bullzeye95

2008-12-08 14:43:47

You may also want to add that there is "IfNDef," "Else," "Undef," etc.

lordsaturn

2008-12-08 14:51:25

Maybe add a real example aswell?

Magiic

2008-12-08 15:15:40

@LordSaturn
{$Define SMART}
program new;
{$IfDef SMART}
{.include srl/srl/misc/Smart.scar}
{$EndIf}
{.include srl/srl.scar}

begin
SetupSRL
{$IfDef SMART}
SmartSetupEx(103, false, true, false);
SetTargetDC(SmartGetDC);
{$EndIf}
end.

Hugolord

2008-12-08 15:17:50

An example besides SMART?

Anyway, good tut.

Magiic

2008-12-08 15:22:17

ok then Hugo here you go ;)
{$Define I}
program new;
{.include srl/srl.scar}
var
I : integer;

begin
SetupSRL
for I:=0 to 10 do
{$IfDef I}
WriteLn(IntToStr(I));
{$EndIf}
end.

noidea

2008-12-08 15:26:21

I still don't get exactly what it does :confused:

Magiic

2008-12-08 15:34:54

it allows you to do something when you define it or stop something happening when it hasn't been defined

Blumblebee

2008-12-08 15:37:14

the only thing i dont understand is how it know when you want I to be defined or not :/

Magiic

2008-12-08 15:39:47

you comment it out ;) like
//{$define }
rather than
{$define }

lordsaturn

2009-02-04 06:49:53

Sorry for the bump, but are you able to include during runtime?

begin
{$IfDef SMART}
{.include srl/srl/misc/Smart.scar}
{$EndIf}
end.

Baked0420

2009-02-04 07:10:21

look at SandoS' examle, it shows that you can. He did:


begin
SetupSRL
{$IfDef SMART}
SmartSetupEx(103, false, true, false);
SetTargetDC(SmartGetDC);
{$EndIf}
end.

lordsaturn

2009-02-04 07:13:39

That's not what I'm asking though. I was asking if you could include files during runtime. That example just shows him setting up SMART.

bullzeye95

2009-02-04 07:38:19

It doesn't include it during runtime; only when the script is compiled (notice: "compiler" directives).

Baked0420

2009-02-04 07:41:22

oh sorry lordsaturn, I misunderstood your question. I thought you meant could you just use define during main loop.