<Variables>Our next view point will be variables and constants. I would highly advise you to at least look over that section in my other guide. I will only explain it briefly, and will drown you with examples.
Variables and constants store data. This is the same as saying that they represent certain numbers or characters. Variables can be changed during the script, while constants will always be the same. You will see this through some of my examples.
First we declare the variable. (Tell Scar that we are using the name as Integer, String, or Boolean).
1. Copy down my example.
program Vars;
var
i, sum: Integer;
Hello: String;
begin
//In the next example
{I will explain how to use it}
end.2. Study the example.
In this example, there are 2 types of variables: integers (whole positive and negative numbers) and strings (any characters; AKA: what you use as text for SendKeys. We will touch booleans (true and false) later. If you are very confused and have already read the section in my last tutorial, then bear with me a little.
In my example I used i and sum as integers and Hello as a string. You can name your variables anything you want. You can also declare more than one of the same variables (if they’re of the same kind: integers, strings, etc.) on the same line; just separate them with a comma.
EXTRA!I used // and { } for commenting. In code, those will appear green. There are two ways to use comments. One way is to put // in front of what you want to comment. This will make the rest of the line a comment. The other way is to use { }. Whatever is between { } will be a comment. Comments are used to leave yourself notes or directions for the user of your script.
3. Copy the following example.
program Vars;
var
i, sum: Integer;
Time: Integer;
begin
i:= 1;
sum:= i+1;
WriteLn(‘The sum is ‘ + IntToStr(sum));
Time:= 100;
Wait(Time);
end.4. Study the model.
You should already know how to tell Scar which variables to use. (i: Integer;) Now you can see how to tell Scar what the integer is. In this example I made code see i as 1 (i:= 1;). Then, I told ScarS that sum is equal to whatever i is equal to, plus one (sum:= i+1;).
Then, I told Scar to print out, in the debug box, what the integer sum is. To do this, I used a new function called IntToStr. IntToStr can be added to WriteLn, SendKeys and other typing functions. You must put the integer (in this case “sum”) between ( ) after IntToStr to indicate which integer to use.
After this, I told Scar what the integer Time was. Time:= 100;. Now look at the next part. You see how I replaced the amount to wait (Like Wait(100) ) with the integer Time. Because I told Scar that Time is 100, Scar sees Time as 100 anywhere I put it. You can do this with many other commands. MoveMouse or ClickMouse are just a few that you can use that with.
5. Play around with variables for a bit. You will discover that you can use Scar as a virtual calculator.
REMEMBER!
+ = add
- = minus
* = multiply
/ = divideEXTRA!Randomizing your script is essential to macro on RuneScape. To randomize something, you would type +random(n) after a number you want to randomize. n would be the amount to randomize. Here’s an example.
program Randoms;
var
i: Integer;
begin
i:= 3+random(5);
WriteLn(IntToStr(i));
Wait(200+random(100));
MoveMouse(2+random(4), 6-random(4);
end.I first told Scar that i is going to be an integer. Then I said that i is 3 and a random of 0-4 added onto it. Then we told Scar to write what i is in the Debug Box. Next, we told Scar to Wait 200 milliseconds and a random of 0-99 milliseconds added on to that. Finally, we told Scar to move to the coordinates of 2 and random of 0-3 added for x, and 6 and random of 0-3 subtracted for y.
6. Try to randomize some of your scripts.
Now let’s see how to use strings.
As we said before, strings are characters (text).
7. Copy the following example.
program Vars;
var
Hello: String;
begin
Hello:= ‘How is everyone doing?’;
WriteLn(Hello);
Hello:= ‘Hi’;
WriteLn(Hello);
end.8. Study the model.
As you can tell, strings are pretty much used the same as integers, except they are used with typing functions (WriteLn). I first declared Hello as a String. (Hello: String;). I then said that Hello:= ‘How is everyone doing?’;. Now wherever I put Hello, Scar will see it as ‘How is everyone doing?’. I told Scar to print whatever Hello is inside the Debug Box. Next, I renamed Hello and made it something else. This can be done with integers also.
Remember how I said that variables are special because you can change them inside the script? Well, this is it. All you do is tell Scar that Hello represents something else from now on.
9. Play around with the concept of Variables. Try incorporating it in your old scripts, or making a new one to test how much you have learned.
<Constants>Once you master Variables, Constants should be a piece of cake.
As you have learned in your lesson with variables, Scar uses names to represents things like text or numbers. You also learned that variables can be changed throughout the script.
This is where constants are different. You can only tell Scar what a constant represents once, at the beginning of your script. This is very good to give the user of your script options like wait times, text to type, and color numbers to search for (we will learn colors later).
This is how we declare constants (Tell what they represent)
1. Copy the following example.
program Constants;
const
WaitTime = 100;//Time To wait
WhatToType = ‘Hello, I am cool.’;//What to type
begin
Wait(WaitTime);
WriteLn(WhatToType);
end.2. Study the script for a while.
We declare constants after the program Name and before begin. Unlike variables, we tell Scar what constants represent right away (WaitTime = 100;). Then, we use them the same way that we use variables.
I this example I made Scar wait whatever WaitTime stood for. Then, I made it type whatever WhatToType stood for inside the debug box.
You see! Once you understand variables, constants come natural.

3. Incorporate Variables and Constants into your older scripts or make a new one to see how much you have learned.
REMEMBER!
Variables can be changed throughout the whole script.
Constants can only be declared once. You may not change it within the script.<Loops>
By now you must be wondering, “But how do they make the script run forever?”
I will teach you how to “loop” your script in this section. This will allow your script to run forever or as many times as you will it.
Let’s look at an example.
1. Copy the following example.
program Loops;
begin
repeat //Place repeat before what you want to repeat
WriteLn(‘I want to wait forever!’);
Wait(100);
until(false); //Place where you want repeat to stop
end.2. Study the model a little and try to run it on your own, personal Scar client.
Here you see your first loop. There are many different kinds of loops. This is the first and simplest loop we will look at.
To start this loop, we place repeat before what we want the script to repeat. After we finish writing the commands we want Scar to repeat, we put an until.
Until has options. The option we used this time was until(false);. This tells Scar to go on forever. The only way this script will stop is if you press stop.
Remember how I said that you put repeat before what you wanted the script to repeat? I’ll show you an example to further that a little further.
3. Add this onto the old example or just copy paste over the old one.
program Loops;
begin
ClearDebug; //Scar will only do this once
repeat //Place repeat before what you want to repeat
WriteLn(‘I want to wait forever!’);
Wait(100);
until(false); //Place where you want repeat to stop
WriteLn(‘I guess this will never be written, since the above loop goes forever :/’);
end.4. Study what I have added and notice the differences between the earlier scripts.
5. Run the script and discover how it is different from the last one.
In this example, I told Scar to ClearDebug (Clear Debug box) before starting the loop (repeat). Then I told Scar to WriteLn and Wait. I told Scar to never stop repeating what is between repeat and until by telling it until(false);.
As you can see, you do not have to have repeat at the beginning of your script. Just set it wherever you want it to repeat from.
You’re probably pretty edgy on seeing that last WriteLn being shown now, eh?

Don’t worry, with this next part, your loop doesn’t have to go forever.
You must remember how to use variables for this next part. This part should be pretty simple.
6. Copy down the following example.
program CountingLoops;
var
i: Integer;
begin
ClearDebug;
i:= 0;
repeat
i:= i + 1;
WriteLn(‘This is loop number ‘ + IntToStr(i));
Wait(100);
until(i = 2);
WriteLn(‘Thought you’d never see me, huh?’);
end.7. Study the example a little.
As I warned you, we use integers for loops that go an amount of times. For this example, I chose an integer named i. I first told Scar to ClearDebug. I then said that i is 0. Next, I said that the loop will begin here.
Now you see the i:= i + 1; after repeat? Since i is 0, we have just added one to 0, thus making i 1. (Since i=0, 0+1=1)
The reason I told Scar that i is whatever number i represented before plus one, is to count the amount of loops the script has gone through (How many times it has gone from repeat to until). Then, I told Scar to do a bunch of stuff (WriteLn and Wait).
The next part is what makes this script work the amount of times you want it to. Remember that in our last script we used until(false); to tell Scar to never stop the loop. Well, this time we gave Scar another condition. We told Scar to repeat the loop until i is 2.
You see! That is how our earlier integer, i, ties into this. Since, it constantly adds one to itself with every loop it goes through, Scar will stop the loop when i becomes 1.
Finally, we can see the WriteLn we could not see before. I guess the little bugger learned a way to show up, now. :p
REMEMBER!
= - Equal to
< - Greater than
> - Less than
<= - Greater than or equal to
>= - Less than or equal to
<> - Not equal toUse those with to tell Scar when to stop loops (until(i > 4)

.
8. Play around with the repeat loop for a little while. When you’re ready, continue to the next part.
I won’t explain the next part too much. I told you earlier that there are different kinds of loops. I will show you a few of these through examples. Try to study the examples a little before going away disappointed

.
program OtherLoops;
var
i: Integer;
begin
i:= 0;
while(i < 6) do
i:= i + 1;
WriteLn(‘Hullo number ‘ + IntToStr(i));
end.Simply put, it goes like this. I made i 0. I told Scar while i is less than 6, make i equal itself plus one and WriteLn.
program OtherLoops;
var
i: Integer;
begin
for i: = 0 to 5 do
i:= i + 1;
WriteLn(‘Loop number ‘ + IntToStr(i));
end.This loop works like this. i is 0. While i is going from 0 to 5, do the following. Then I made i equal itself plus one and made Scar WriteLn.
I hope the last two loop types were not too confusing. If you are confused, keep studying the examples. By making scripts that use different kinds of loops, you will learn how to use them.
EXTRA!Sub-Begin and Sub-End;
This is something that you should learn before we go to the next step.
In general, there is the main loop. This is the begin end. However, there can be many tiny sections inside the main loop. You might need to separate them to make your life easier while editing scripts. This will also help you later when we learn if then else procedures.
program SubBeginAndEnd;
var
i: Integer;
begin
ClearDebug;
i:= 0;
repeat
begin
i:= i + 1;
WriteLn(‘Hi!’);
Wait(100+random(10));
end;
until(i = 5);
WriteLn(‘That is how we use sub-begin and end.’);
end.9. Study this a little.
You see how I created a small sub-section in the main loop to make my script look neater, and to make that section easier to locate later if I wish to edit my script.
You can do this anywhere in the main loop, but remember that every begin must have an end. If you have 3 begins and 2 ends, you will get an error. Also remember that every end, except for the last one, will have ; following it.
<Procedures>Procedures become simpler once you see some examples, but just know this: Procedures are used to reduce the amount you have to type out.
Procedures have their own loop. Remember that Scar will only do what you tell it in the main loop (last begin and end). Procedures have to be called on (Write the procedures name) in the main loop. If you’re confused, look at the following example.
1. Copy this example.
program Procedures;
procedure Write; //procedure name (like program name)
begin
WriteLn(‘I love pizza’);//what to do in procedure
Wait(100);
end;
begin
Write; //use the procedure in main loop
end.2. Study this example.
In this example I made a procedure named Write. You have to name procedures the same way you name the program. Next, I told Scar that the procedure will first WriteLn and then Wait.
Notice how I made the procedure have its own begin and end.
Next, I had to include the procedure name in the main loop to tell Scar to do what the procedure does.
3. Make your own script using a procedure.
4. Copy the following example.
program Procedures;
var
i: Integer;
procedure Move;
begin
repeat
begin
i:= i+1;
Wait(100);
MoveMouse(200, 200);
end;
until(i = 2);
end;
procedure Combine;
var x: Integer;
begin
ClearDebug;
for x := 0 to 3 do
x:= x + 1;
Wait(100);
WriteLn('Greetings All');
Move;
end;
begin
Combine;
end.5. Study the example a bit.
In this example, I used multiple procedures. If you study the first procedure you will see how a procedure is a bit like its own loop. It can have more begin and ends and can have repeating loops. The first procedure Starts a repeat. I told Scar to Wait then MoveMouse. It will do this three times.
Next you see the procedure Combine. Study it a bit and you will see something strange.
In this procedure I included a variable inside the procedure. Yup, you can do this. However, since I made the variable only for the procedure, other procedures won’t see it. This means that if you included x:= 0 in the main loop or another procedure, Scar would tell you that it doesn’t know a variable named x.
In this script I used a for loop to tell Scar what to do three times. I told it to Wait, WriteLn, and then do whatever Move stands for doing.
Finally, I included the procedure Combine in the main loop to tell Scar to do whatever Combine does.
6. Experiment with this a bit. See what you can come up with.