SRL Archive - OSR Outdated Tutorials

Creating Your VERY Own Includes!


Daniel

2007-12-27 05:21:44

This tutorial is still under development. It is noted so you understand.


Creating your own includes
~~By Dan's The Man~~


This tutorial is detailed (has a lot of lines) and is used for beginner scripters to creating their own include. For a list of requirements, please see the requirements for more information.

Table Of Contents:
1:……Introduction.
2:……Requirements.
3:……Creating a function/procedure.
4:……Adding Brackets.
5:……Testing that function/procedure.
6:……Adding information.
7:……Including an include.
8:……Distributing To Public.

Introduction:
This tutorial is basically all about creating your very own includes. Some includes can contain a lot of space and they always contain functions/procedures. An include never contains a main loop, and always contains information on what that certain function/procedure does above it.

Requirements:
- Basic Knowledge of SCAR
- Knowledge of Loops
- Knowledge of Variables/Arrays (Either one does not matter).
- What is a string. What is an integer. What is a boolean.
- Knowledge of Procedures

Creating a function/procedure:
For an include to work, you require some functions or procedures. A function always returns a value, whether it is a boolean (True or False), a string (Words) or a integer (Numbers). A procedure does not return a value but is a joint of functions together.

Now, first you'll be learning how to create a function. Creating a function is very simple if you know how to make procedures. It is practically the same but adding a little more information/stuff into them. So, instead of adding Procedure before a name of a procedure, i add Function instead. In this example, i'll name my function NewFunction
function NewFunction;
Now that will not work because i have not set whether the function will return a string, integer or boolean. In this example, i will be showing you how to include a boolean. So, i would add ": Boolean" after the script name. Now i would add a begin and an end, just like a procedure. So now my NewFunction would look like this:

function NewFunction: Boolean;
begin
end;
Similar to a procedure, isn't it? Now, in this example, the NewFunction function will try to find a colour then return a true or false statement. So, if i wanted it to find red (255) i would add an if(…) then statement. You should know how to do this if you have a basic knowledge of SCAR. I want my function to search for the colour in a specified box from x:500 y:500 to x:600 y:600. I would also need to declare x and y as a variable, you declare variables above the begin. My new function should look like this so far
Function NewFunction: Boolean;
Var x : boolean;
Var y : integer;
Begin
If(FindColor(x,y,255,500,500,600,600)) Then Result:=True;
End;
That will only search for the colour once and then return true or false. Now, i want my function to keep repeating the if(…) then statement until it has found a colour. So, basically i add a loop, which is repeat and to end the loop i would put Until(…);. So, for my new function to keep repeating until it has found the colour, i would have to add "Result=True" in the Until bracket area. So my new function should look like this now:
Function NewFunction: Boolean;
Var x : boolean;
Var y : integer;
Begin
Repeat
If(FindColor(x,y,255,500,500,600,600)) Then Result:=True;
Until(result=True);
End;
Finally, my function is ready for use.

Now onto the procedure's part. A procedure is part of a script that does a lot of functions. Whether you set which functions to be in a procedure or not. To create a procedure, you would have to add procedure instead of function because it is not a function is it? It does not return a value so it cannot be a function.

Now, i want my procedure to do the NewFunction then move my mouse to that spot. So, you should know how to set-up a procedure, it should look like this:
procedure NewProcedure;
begin
end;
My new procedure is called NewProcedure in this example. Ok, so now i will add NewFunction a line after the begin so it will do the function we made before, NewFunction. Which is an if(…) then statement which will search for red and repeat until it has found it. Ok, so i want to move my mouse to the area where that red colour is found. So, i will add MoveMouse after NewFunction. Ok, so my updated procedure should look like this:
procedure NewProcedure;
begin
NewFunction;
MoveMouse(x,y);
end;
Now, it will move the mouse to where i found the red colour. But i want it to write in the debug box if it has actually found it. So now i will have to add Writeln('Has found colour'); after MoveMouse. So i will do that. That is all i want to do. So, that is my new procedure done.

Adding Brackets:
In some functions/procedures, it allows you to add your own information. For a user to input data, you'll need to put brackets after the procedure/function name. In this example, i will be modifying my function so a user can input data. For example, the SendKeys function has brackets to allow the user to input what to say. SendKeys('Hello'); would type the text hello. You can change hello to whatever you want. So, in this brackets example, i will be changing my NewFunction so the user can choose what colour to press. Ok, so now i add brackets after the name, like so:

Function NewFunction(): Boolean;
Var x : boolean;
Var y : integer;
Begin
Repeat
If(FindColor(x,y,255,500,500,600,600)) Then Result:=True;
Until(result=True);
End;
So now we have the brackets ready, i will put the word colour and declare colour as an integer, because it requires a user to input a number. So, my new function now looks like this:

Function NewFunction(colour: integer): Boolean;
Var x : boolean;
Var y : integer;
Begin
Repeat
If(FindColor(x,y,255,500,500,600,600)) Then Result:=True;
Until(result=True);
End;
But that is not just finished yet because it will still find the colour red. You see in the if(…) then statement it will still search for the colour 255. So i replace 255 with colour, in this case colour is kind of like a constant. Well, my new function will now look like this:

Function NewFunction(colour: integer): Boolean;
Var x : boolean;
Var y : integer;
Begin
Repeat
If(FindColor(x,y,colour,500,500,600,600)) Then Result:=True;
Until(result=True);
End;

Testing that function/procedure:
To test a function/procedure, is very simple. Before you release your include, you should always test out your function to see if it actually works instead of compiling. Ok, just add a main loop at the end of your include, like this:

begin
end.
Now implement your include into the main line. Like, i will for my NewFunction:

begin
NewFunction;
end.
Ok, that will not work because i did not input entries, which are the bracket. So i'll do so like this:

begin
NewFunction(0);
end.
More Coming Soon…


Adding Information:
Information is basically information about your function or procedure so others can understand it. Most include has it, especially SRL, above every function/procedure. This can be the description of that new procedure/function (What it does), the author and the name of it (procedure BlahBlah;). It is commented so the script will not return errors when you run it. To add a comment, just add a { to start it and an } to end it.

Including an Include:
So, now that you have saved your include inside the includes folder, you might want to have that procedure or function in your own separate script. Now, since you saved the include as "testinclude.scar" (or whatever the name is) you'll need to add it into your own script. Ok, so click on New Script button and a new script will be made.
More Information Coming Soon (Tomorrow)…

Distributing to the Public:
Coming Soon (Tomorrow)…

Naum

2007-12-27 05:38:45

Good work. Add some more to it and a rep++ comming your way :):0:0:)

Killerdou

2007-12-27 05:46:41

your examples wouldnt compile^^

Daniel

2007-12-27 05:47:52

From: NaumanAkhlaq
Good work. Add some more to it and a rep++ comming your way :):0:0:)

I am going to add some more tomorrow. Right now i am tired and just waking up for some unknown reason, so i check the comp. Lol, fell asleep about 15 mins ago and woke back up :'(

Besides, my mind isn't straight at the moment.

Daniel

2008-01-06 20:19:07

OMFG :mad: :mad: :mad: :mad: :mad: :mad:

Fricking Firefox crashed and i lost all my data. God Damn It!!!

I'll continue this tomorrow because my head is exploding :mad: :mad: :mad:

skillsman

2008-01-13 15:57:25

So if i was missing an include in a script i downloaded off this site, could i make my own include for it?

Macro_FTW

2008-01-14 08:16:12

Good tutorial. + Rep.

Only one little problem- put in a fail-safe in the loop:


Var y, c : integer;
Begin
Repeat
If(FindColor(x,y,255,500,500,600,600)) Then Result:=True;
c:=c+1;
Until(result=True or c=10);

The only reason that I'm putting that in there is to teach new scripters to put in things to break a loop.

Once again, good guide though :D

ZephyrsFury

2008-01-14 08:39:23

From: skillsman
So if i was missing an include in a script i downloaded off this site, could i make my own include for it?


Well the point of an include is so that more than one script can access the same functions/procedures/types, etc. with out having to copy the whole code into the script. So yes if you are missing an include you could make your own but it would need to be exactly the same as the original include. :p It would be better to get the original.

@IP, your guide is good and explains your ideas well.

Rikje

2008-01-14 10:14:05

Instand of

until(Result = True);

you could also use

until(Result);

;)

nething

2008-01-14 14:26:37

Nice. Don't think I will be making my own includes any time soon but that helps me understand the SRL includes a bit more. :)

Daniel

2008-01-15 20:22:39

From: ZephyrsFury
@IP, your guide is good and explains your ideas well.


Thanks and i am discontinuing this project as when ever i press the save button it downloads a file called newthread.php and new tabs keep opening up on blank pages. So, Mods/Admins feel free to edit, change any data and most importantly add the rest.

Thanks!

BazzBarrett

2008-12-04 17:33:21

noone else notice you declered x as boolean? i think tahts suppost to be an integer.

Daniel

2010-07-05 00:39:29

From: BazzBarrett
noone else notice you declered x as boolean? i think tahts suppost to be an integer.


I think it's supposed to be too <_>

i luffs yeww

2010-07-05 14:51:16

Also, update/add this. :)