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 NewFunctionNow 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:
SCAR Code:
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
SCAR Code:
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:
SCAR Code:
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:
SCAR Code:
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:
SCAR Code:
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:
SCAR Code:
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:
SCAR Code:
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:
SCAR Code:
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:Now implement your include into the main line. Like, i will for my NewFunction:Ok, that will not work because i did not input entries, which are the bracket. So i'll do so like this:
SCAR Code:
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)...