SRL Archive - OSR Advanced Scripting Tutorials

[Tut]Making your OWN includes![Tut]


Rich

2008-09-25 11:08:58

How To Make Your Own Includes

By Richard

In this tutorial, I am going to show you how to make your very own includes…Yes, just like the SRL includes. Sound difficult? Well read on and see what you think then!

Yesterday, I was experimenting around with SCAR, as I do. I ended up wondering whether I could shorten a command, let's say
TerminateScript;
to something like
TS;
…So I gave it a shot.


When you are making a script, you normally include
SetupSRL;
But do you know what it actually is? It's made up of many different commands:
procedure SetupSRL;
begin
MouseSpeed := 15;
CheckHPFirst := True;
Reincarnate := False;
TalkAfterRandoms := False;
RoadColor := 0;
WaterColor := 0;
BankColor := 0;
LampSkill := 'mining';
SetUpSRLReport;
LoadCosineArrays;
SymbolAccuracy:= 0.8;
LoadNPCArray;
LoadSRLBitMaps;
SolveChatRandoms := True;
SetupSRLAutoResponder;
UseFindMod := True;
LogoutOnMod := True;
UseFindTrade := True;
Screenshots := False;
InitializeSRLLogFile;
Writeln ('SRL Compiled in '+ IntToStr(GetTimeRunning) + ' msec');
end;

To do this, however, you need to add an include. Which one to be exact? The one that you see in most scripts:
{.include SRL/SRL.scar}
If you open that file, you will see that SetupSRL is in there as a procedure. Getting the hang of it now?

To make your own, you will need to do something like the above. To start you off, let's keep it simple.

In this example, I am going to do what I said above; simplify
TerminateScript;
Open up a new SCAR window. All you'll see right now is this:


You don't need
program New;
so change it to
procedure TS;
If you don't do the above, it won't work. I hope you can see where I'm getting now.

In this procedure, add
TerminateScript;
So now we have:

THE PICTURE DOESN'T WORK ANYMORE AND I CBA TO MAKE ANOTHER ONE. SORRY!

You can add something else, like
WriteLn('Woo! Richard rules!');
above
TerminateScript;
I suggest you do something like that so that you can see it works. Save it as
TestInclude
in the includes folder. This is your own include!


Now open up another SCAR window. Because we have to include includes (duh!), below
program New;
of the new SCAR, we add
{.include TestInclude.scar}
Now just add
TS;
in between
begin
and
end.
Now we have our second script as:


Press and see what happens!

I'll give a quick run down of what just happened, and how it works.

You named a procedure "TS" in your include script, which is how you call upon it in your other script. You saved it as "TestInclude", in your includes folder, which is how you include it in your script.

It really is as simple as that!

Of course, in the file where you saved TS, you could have many more procedures and functions, to make it much more useful. If you are not sure what I mean, open up a .scar in the includes folder, and see what I mean.

Please give feedback on how you think this tutorial is, and how it could be improved. Thanks!

Heavenzeyez1

2008-09-25 12:20:30

Well explained, good.
~Eerik~

sirlaughsalot

2008-09-25 12:23:48

Good, but give final results so people can compare/contrast, and give a screenshot of where to save it :D

Rich

2008-09-25 12:29:40

Thanks for the feedback guys.

Sirlaughsalot, I have included some pictures of final scripts, but they weren't showing, so I changed the host and now they are. I'll add a picture of the file in a minute.

simple skill

2008-09-25 16:15:27

thanks for this it will help me when i get into scripting

footballjds

2009-04-30 20:17:47

and this:

program old;
procedure TS;
begin
TerminateScript;
end;
begin
TS;
end;

works ROFL!!! use that instead of including if all you wana do is make TerminateScript shorter… ROFL!!! :D