Brown
03-10-2006, 04:45 AM
Well, Im known to some at other SCAR forums and I just got to SRL. Ive been scripting SCAR for a while, so I decided to write an easy to follow tutorial teaching you how to use variables, colors(<will come soon) , and incorporating variables into repeats. Only read this tutorial if you atleast know basic commands (movemouse, clickmouse, writein, yadayadayada).
Variables
Basics of variables: A variable allows different things to happen in a script depending on different factors. Example of how one works - If the script finds the color RED at point 1,1 then move the mouse to point 50,50. Variables also have other uses wich will be described in the tut.
Making a simple variable:
Step 1: Telling SCAR to use variables
To start a variable you must place a new section into your script. Write var on a line after "program New;" to tell scar that you will be using variables.
program New;
var
begin
end.
Step 2: Defining variable names.
On lines after "var" and before "begin" you can begin to tell it what variables you want. There are different types of variables, I will show you how to use the 2 most commonly used variables.
program New;
var
//Below you give a variable a name, and a type.
Variable1:boolean;
Variable2:integer;
begin
end.
The 2 most used are Integer, and Boolean variables. Integer variables use numbers, boolean is true/false variables. I put in Variable1:boolean; saying that variable one is going to be a true/false variable. The names of the variable can be anything from Cheat to Donkey, you decide. In this case I chose to name mine variable 1 and 2 to be easy.
(At this point it might not make sense, but it will later on in the tutorial.)
Step 3: Setting Values.
Before a boolean(true/false) or an integer(number) variable can do you anything at all, you must have a place to tell it what its value its. (true or false, 1 or 3432523)
program New;
var
Variable1:boolean;
Variable2:integer;
begin
//Below is where you set the value for each variable.
Variable1:=true;
Variable2:=23;
begin
//Your commands will be here.
end;
end.
Right after begin you can say what the variable's values are. For 1 I put true, and for 2 I put 23. The variables must follow what you told them to be. Variable 1 is boolean, therefore it must be true or false, variable 2 is integer so it must be a number.
Notice I added another Begin and End, between those is where your commands will go.
Step 4: Putting boolean Variables to use.
Finally we get to do something with the variables.
Variables in code form are pretty easy to understand.
In the code you will easily notice how they work.
program New;
var
Variable1:boolean;
Variable2:integer;
begin
Variable1:=true;
Variable2:=23;
begin
if (Variable1=true) then
begin
movemouse (1,1)
end;
if (Variable1=false) then
begin
movemouse (45,45)
end;
end;
end.
I think that is mostly self explanitory for boolean. Notice I used separate begins and ends for each variable, this prevents the variable from playing commands that you dont want it to play. (In most cases its not needed, but its always safer to have them). As you can see from the script above, if you put true in for Variable1, it will move the move the mouse to 1,1. If false it goes to 45,45. (try running the script to see what happens)
Step 4: Putting Integer Variables to use.
If you dont understand boolean from above, go back, go back, go back. This part is where it gets more advanced.
Using integers for repeating.
In a basic repeat script, you can use integer variables to tell it how many times to repeat.
If you want to make a script repeat a certian amount of times, you hafta tell the integer variable to go up by 1 everytime the requested area is played.
First add another integer variable that will be used as an increasing value.
Then add the repeat command and an until after it.
Then place I:=+1; between the 2. This says that "I" will increase everytime things repeat.
Then put in some basic commands that you want to repeat between "repeat" and "until". (after "i:=i+1;")
For until put "until (i=(variable2));", this says it will stop when i gets to variable 2, wich is 23 right now.
program New;
var
Variable1:boolean;
Variable2:integer;
I:integer;
begin
Variable1:=true;
Variable2:=23;
begin
repeat
i:=i+1;
movemouse (1,1)
wait (10)
movemouse (100,100)
wait (10)
until (i=(variable2));
end;
end.
Probably a bit confusing, but lets break it down. First we tell it to repeat. Second, the i:=i+1 just means 'I' increases every time it repeats. Then we have some commands for it to repeat. Now at the "until" part it basicly says that when the increasing variable "i" reaches the number put in for variable2 the repeating will stop. Try the script out, change the value of variable2 to change how many times it will repeat now.
---------------------------------------------------------------------------------------------
This explains the basics of variables, in depth. Use this knowledge and try making some small scripts for your self. As it says in the beggining of the post, there will be color picking and finding incorporated into variables, but I just spent 1 and 1/2 hours typing this so it will come another day.
Hope you like it.
Variables
Basics of variables: A variable allows different things to happen in a script depending on different factors. Example of how one works - If the script finds the color RED at point 1,1 then move the mouse to point 50,50. Variables also have other uses wich will be described in the tut.
Making a simple variable:
Step 1: Telling SCAR to use variables
To start a variable you must place a new section into your script. Write var on a line after "program New;" to tell scar that you will be using variables.
program New;
var
begin
end.
Step 2: Defining variable names.
On lines after "var" and before "begin" you can begin to tell it what variables you want. There are different types of variables, I will show you how to use the 2 most commonly used variables.
program New;
var
//Below you give a variable a name, and a type.
Variable1:boolean;
Variable2:integer;
begin
end.
The 2 most used are Integer, and Boolean variables. Integer variables use numbers, boolean is true/false variables. I put in Variable1:boolean; saying that variable one is going to be a true/false variable. The names of the variable can be anything from Cheat to Donkey, you decide. In this case I chose to name mine variable 1 and 2 to be easy.
(At this point it might not make sense, but it will later on in the tutorial.)
Step 3: Setting Values.
Before a boolean(true/false) or an integer(number) variable can do you anything at all, you must have a place to tell it what its value its. (true or false, 1 or 3432523)
program New;
var
Variable1:boolean;
Variable2:integer;
begin
//Below is where you set the value for each variable.
Variable1:=true;
Variable2:=23;
begin
//Your commands will be here.
end;
end.
Right after begin you can say what the variable's values are. For 1 I put true, and for 2 I put 23. The variables must follow what you told them to be. Variable 1 is boolean, therefore it must be true or false, variable 2 is integer so it must be a number.
Notice I added another Begin and End, between those is where your commands will go.
Step 4: Putting boolean Variables to use.
Finally we get to do something with the variables.
Variables in code form are pretty easy to understand.
In the code you will easily notice how they work.
program New;
var
Variable1:boolean;
Variable2:integer;
begin
Variable1:=true;
Variable2:=23;
begin
if (Variable1=true) then
begin
movemouse (1,1)
end;
if (Variable1=false) then
begin
movemouse (45,45)
end;
end;
end.
I think that is mostly self explanitory for boolean. Notice I used separate begins and ends for each variable, this prevents the variable from playing commands that you dont want it to play. (In most cases its not needed, but its always safer to have them). As you can see from the script above, if you put true in for Variable1, it will move the move the mouse to 1,1. If false it goes to 45,45. (try running the script to see what happens)
Step 4: Putting Integer Variables to use.
If you dont understand boolean from above, go back, go back, go back. This part is where it gets more advanced.
Using integers for repeating.
In a basic repeat script, you can use integer variables to tell it how many times to repeat.
If you want to make a script repeat a certian amount of times, you hafta tell the integer variable to go up by 1 everytime the requested area is played.
First add another integer variable that will be used as an increasing value.
Then add the repeat command and an until after it.
Then place I:=+1; between the 2. This says that "I" will increase everytime things repeat.
Then put in some basic commands that you want to repeat between "repeat" and "until". (after "i:=i+1;")
For until put "until (i=(variable2));", this says it will stop when i gets to variable 2, wich is 23 right now.
program New;
var
Variable1:boolean;
Variable2:integer;
I:integer;
begin
Variable1:=true;
Variable2:=23;
begin
repeat
i:=i+1;
movemouse (1,1)
wait (10)
movemouse (100,100)
wait (10)
until (i=(variable2));
end;
end.
Probably a bit confusing, but lets break it down. First we tell it to repeat. Second, the i:=i+1 just means 'I' increases every time it repeats. Then we have some commands for it to repeat. Now at the "until" part it basicly says that when the increasing variable "i" reaches the number put in for variable2 the repeating will stop. Try the script out, change the value of variable2 to change how many times it will repeat now.
---------------------------------------------------------------------------------------------
This explains the basics of variables, in depth. Use this knowledge and try making some small scripts for your self. As it says in the beggining of the post, there will be color picking and finding incorporated into variables, but I just spent 1 and 1/2 hours typing this so it will come another day.
Hope you like it.