PDA

View Full Version : Basic Scar Variables and Colors



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.

Bam Bam
03-13-2006, 01:17 AM
aww no array tutorial yet...

weaselforce
03-13-2006, 02:25 AM
thank you very much, not being a scriptor myself its great to have someone helping me understand scripts

Jagex_Fagex
03-13-2006, 08:00 AM
aww no array tutorial yet...

u want array tutorial... ask kane

XxKanexX
03-13-2006, 08:31 AM
u want array tutorial... ask kane
It was deleted, remember? :(

Jagex_Fagex
03-13-2006, 09:23 AM
what is it with people not backing up tuts :eek: :rolleyes:

XxKanexX
03-13-2006, 09:56 AM
what is it with people not backing up tuts :eek: :rolleyes:
I thought Kait wouldn't close.

Jagex_Fagex
03-13-2006, 10:31 AM
Yeah, no 1 did :( :( :(

Brown
03-14-2006, 12:03 AM
:( 7 posts in the topic and only one about my tut (thanks weasel). Could anyone post suggestions on ways to improve it?

Bam Bam
03-14-2006, 12:59 AM
Add ARRAYS!!!!

Brown
03-14-2006, 04:12 AM
Unfortunatley I only saw the array tutorial once, so I couldnt possible make an accurate tutorial on it :P.

timmyboy
03-14-2006, 02:48 PM
It's all a very nice tutorial, good job. There's one thing I don't understand though(stupid me). How would you get the script to change Variable1=true to Variable1=false? Sorry if I'm confusing you, i'm just starting to learn how to script in Scar.(it's different from JS:p)

Brown
03-14-2006, 09:06 PM
It's all a very nice tutorial, good job. There's one thing I don't understand though(stupid me). How would you get the script to change Variable1=true to Variable1=false? Sorry if I'm confusing you, i'm just starting to learn how to script in Scar.(it's different from JS:p)
Heres my snippet of Step 3.

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.
After you declare the variable's type, you go to the begin section. Right after begin you type in the values using the syntax showed. I will italicize the part where you change the values.

papetowe
03-20-2006, 04:16 AM
Thanks, this helped me out.

JAD
02-16-2007, 09:42 PM
thanks for making this tut. the thing that helped me in it was how to make a script repeat itself a certain amount of times (like until i:=23) so thanks for that. something that would make this tutorial better i think though is if you put in a little something on const's, because variables and const's kind of go together. but otherwise great tut, looking forward to seeing the color part of it :P

Bam Bam
02-16-2007, 09:58 PM
Brown, You should consider defining the different types of variables to make it easier for someone first learning like to store an integer declare as integer or to store a true or false use boolean, likewise with strings