Toterache
2007-11-14 11:49:49
EDIT: Finally i forfilled my promise, the entire thing is updated, I hope it makes more sense now. :)
Welcome to my very first tutorial.
This covers the very basic stuff of SCAR like moving the mouse, clicking the mouse, explaining variables and constants, and colors (what they are, how to find them and why they are useful).
1.1) Variables
1.2) Constants
2.1) Moving The Mouse Using Variables
3.1) Colors (What They Are And Their Uses)
3.2) Using All The Things We Learned In One Basic Script
1.1)
Variables are very important things, probably the one thing you will use most, no matter in what kind of script. Variables, like you should have learned in math class, are letters, which represent any kind of number. Now, the neat thing about variables is, that they can be "formed". To better understand this, let's take a look at very basic variables used in every script: "x" and "y".
You should have heard them before (remember those coordinate planes the teacher was trying to teach you in school? This is just that, except that this time, you actually have to understand them). "X" and "y" are just positions on your screen, but the coordinate plane is flipped upside-down, so:
Obviously, the bottom right corner has the highest x and y value, and the top left corner has the lowest x and y value.
Now, Let's pretend you want to find an object on the screen, but the object is moving, so it won't always have the same position. So, let's say its current position is (35,89), but by the time you need your program to click on the object, it is somewhere else, let's say at (95,10). Now, when you start the program, you won't know where the object you want to click on will be by the time it is needed.
This is where the variables come in. Of course, if you just tell your mouse to click on (x,y), your mouse won't click, let alone find the right spot, because they can be anything, from -∞ to +∞ . So, first you will need to tell your program what you want x and y to be. So, you will need a function or procedure to tell your program what you are looking for.
So let's take a look at this example:
So, you should already know what "program", "begin", and "end" mean, but there are two or three new things. First of all, there is the thing called "var", this means that everything below it, until the first semi-colon, is a variable. So, this makes clear that x and y are variables. But, now you might be asking what "integer" stands for. Well, integers are ALL whole numbers (meaning all numbers that don't have decimals). so it could rank from 1 up to 99999999 and more. This needs to be done, because x and y aren't numbers, and you have to tell the program first, that x and y represent numbers (because how the heck can you graph something on a coordinate plane like (255,y) or (x,523) or (x,y)). So the integer just tells that x and y are numbers that are not yet defined.
Now, on to the part where the variables are defined. I used a function here which you can look up in the help manual of SCAR (to do this, just open SCAR and press F1, or click on the option “help” and then select “help” in the drop down menu), but to shorten this, I’ll just post it here:
So, I’ll quickly explain what to do here: x and y are the variables where the destination of the object will be saved. the “var” and “integer” are just there to show what you have to do (for the people which only look at the manual and not the tutorials on how to use the functions). Now, you probably know that every color has a number, that is why “color” is an integer, now you could define the color as a constant, but we aren’t that far yet. ;) All which is left now are the last for variables… well, good thing for you, they are easy to understand. As I told you, for SCAR the entire screen is a coordinate plane, and all those four do is say in what area you want the program to look for the color. Those can be substituted with real number. In my example it will start looking for the color on the top right corner and end at a point 100 pixels right and down. pretty easy, now isn’t it? ;)
1.2)
CONGRATULATIONS, you have just finished the hardest part, const are nothing compared to variables! A constant is just a given number that won't change! For example: You need to find a color, let's say the color blue. Colors are represented with numbers, (Will get to that more in detail when we get to the color chapter) and those numbers, will always be the same, so if the color number is 76854 (I made up that number, it isn't the real number of blue), it will still be 76854 when you will get to it later in the script. That easy.
Still, I think I should put in a little example:
2.1)
So, now you actually want to move the mouse and click on stuff, right? Well, that's just as easy done as said. I will teach you the very basic ones:
MoveMouse(x,y: Integer)
(Moves Mouse Instantly, not at all human-like)
MoveMouseSmooth(x,y: Integer)
(Moves Mouse at human speed(or at least that is what it is SUPPOSED to do))
MoveMouseSmoothEx(x, y: Integer; +random(0),20,40,45,25,20);
(Moves the Mouse in a human way, alosm y favorit mouse function(just keep the numbers after the x and y, don't change them)
ClickMouse(x,y: Integer; True/False: String)
(Clicks the mouse, true=Left mouse button, False= right mouse button)
Now, they can be used, but let me tell you, they are about as undetectable as having an auto responder say: “I am an Autoer! Report me!” and that about every 0.1 seconds. So, how about I’ll let you in on the functions which should be used, if you need to use mouse functions:
Mouse(var x,y: Integer; xc, yc: integer; String: Boolean);
(Now, I couldn’t find the real formula anywhere, so I just made one up, it should be about right. It moves the mouse at a declared speed to a destination. x and y are obvious, xc and yc is how many pixels the click can be away from the real x and y values {so if x is 5 and y is 6, and xc and yc are both 2, then the mouse could click anywhere from 5,6 to 7,8}, the Boolean states if left or right click, true = left, false = right).
MMouse(var x,y: Integer; xc, yc: integer);
(pretty much the same as Mouse, but it doesn’t click, only moves the mouse to given destination).
IMPORTANT: If you use Mouse or MMouse, you have to declare the speed, otherwise it will end up taking 10 minutes to cross the entire screen! The procedure is as follows: MouseSpeed := integer; (will be clearer later)
Uh oh, I just noticed a new term we didn't cover: "string". But this one is just as easy as constants. A string is a text, nothing more. So this entire thread would be just one huge string (generally speaking, there are some integers, too, but let's not be too picky), because it is a text. "true" is a string, and "false" is also a string, because it is something that is written. Another new one is Boolean, it just means true or false, that easy.
Now, it always says <name of the function>(x,y: Integer). So, what you have to do is substitute what you need. So, first of all, the thing integer is not needed, it is just there to explain that those are numbers you need to insert.
NOTE: x and y can also be substituted with normal numbers. This is pretty obvious, but I want to make sure that this is clear.
Now, remember we told the program that x and y are already numbers? So, if it fits our purpose, we can just leave them there. Now, it will recall what the "Find" function said they were supposed to be (so if the blue color was on (55,68), x and y will be (55,68) until another "find" function declares them as something else). Now let's pretend we want to use the Mouse Function and left click on the blue color. It will look something like this:
This is very easy, we declared the mouse speed to be 9, which is pretty reasonable. Then it finds the color in the upper left corner of the screen. If you don’t know how to find out where the coordinates are, use the color picker, or just move your mouse across the screen, SCAR will show you the coordinates. After it found the color, it saves it to x and y. After that the courser will move to the destination, with an accuracy limit of 2 pixels, and then left click. That easy :D.
3.1)
Um… yeah… I just realized while I edited this, I already explained colors pretty well, so guess this chapter is just review. 
Now, we touched upon colors earlier, saying that colors are represented by numbers. Every color has a certain number. You can try it out, just click on the Color Picker in your toolbar, and then on any color you want to use. It will give you the number of the color, and the x and y coordinates of the point where you clicked. Now, you need to get that thing into your script. There are two ways, first putting the number into every single function that uses this color, or give the color a name and put it under constants, so that in the future functions, you just have to re-enter the name instead the entire number of that color. The first option I only named to show both possibilities, I would always put it under constants, for then you can also read what that that color is supposed to stand for. But before we put that into a script, here are a few color finding functions:
FindColor(x, y: Integer; color, xs, ys, xe, ye: Integer)
(Searches for a color in a certain area. xs and ys is where to start (remember that it will search from the top left to bottom right), and xe and ye is where to stop searching. you color has to lie between those corner points)
3.2)
Go ahead and do this with me, you will understand it better and faster this way.
We start of with this:
Now we add the name, variables and constants:
Now use your color picker to pick a unique color, because remember what i said? it will stop the search after it found the first corresponding color.
After you got a color, add it into the constants
Now add the FindColor function and mouse movements:
I'll quickly explain everything again, just incase I didn't explain part of it too well:
So, we named the program we said that x and y are variables, meaning that they can represent any number, then we said that if we say MovieMakerSymbol(or whatever name and color you chose) in a place where a number is supposed to be, we mean 1686498. Then the script begins. At first it will search from the top left corner and end in the bottom right corner. It will stop the search once it found the color, and save those coordinates onto x and y. so at the moment x and y are "real numbers". Then it will move the mouse human-like to that destination, and left click on the position.
Well, now we come to the sad part: the parting. LOL. You have successfully completed the basic stages of Scar scripting, and you are now ready to learn from the masters, and no longer the "chicken" like me :P
Thanks for Reading, please leave comments. I will greatly appreciate them. :)
Welcome to my very first tutorial.
This covers the very basic stuff of SCAR like moving the mouse, clicking the mouse, explaining variables and constants, and colors (what they are, how to find them and why they are useful).
1.1) Variables
1.2) Constants
2.1) Moving The Mouse Using Variables
3.1) Colors (What They Are And Their Uses)
3.2) Using All The Things We Learned In One Basic Script
1.1)
===VARIABLES===
Variables are very important things, probably the one thing you will use most, no matter in what kind of script. Variables, like you should have learned in math class, are letters, which represent any kind of number. Now, the neat thing about variables is, that they can be "formed". To better understand this, let's take a look at very basic variables used in every script: "x" and "y".
You should have heard them before (remember those coordinate planes the teacher was trying to teach you in school? This is just that, except that this time, you actually have to understand them). "X" and "y" are just positions on your screen, but the coordinate plane is flipped upside-down, so:
____(-y)___
|—————|
|—————|
(-x)|—————|(+x)
|—————|
|—————|
(+y)
|—————|
|—————|
(-x)|—————|(+x)
|—————|
|—————|
(+y)
Obviously, the bottom right corner has the highest x and y value, and the top left corner has the lowest x and y value.
Now, Let's pretend you want to find an object on the screen, but the object is moving, so it won't always have the same position. So, let's say its current position is (35,89), but by the time you need your program to click on the object, it is somewhere else, let's say at (95,10). Now, when you start the program, you won't know where the object you want to click on will be by the time it is needed.
This is where the variables come in. Of course, if you just tell your mouse to click on (x,y), your mouse won't click, let alone find the right spot, because they can be anything, from -∞ to +∞ . So, first you will need to tell your program what you want x and y to be. So, you will need a function or procedure to tell your program what you are looking for.
So let's take a look at this example:
Program VariableExplanation;
var
x,y: Integer; //this tells us that they are actually variables
begin
FindColor(x,y, 76854,0,0,100,100)
end.
So, you should already know what "program", "begin", and "end" mean, but there are two or three new things. First of all, there is the thing called "var", this means that everything below it, until the first semi-colon, is a variable. So, this makes clear that x and y are variables. But, now you might be asking what "integer" stands for. Well, integers are ALL whole numbers (meaning all numbers that don't have decimals). so it could rank from 1 up to 99999999 and more. This needs to be done, because x and y aren't numbers, and you have to tell the program first, that x and y represent numbers (because how the heck can you graph something on a coordinate plane like (255,y) or (x,523) or (x,y)). So the integer just tells that x and y are numbers that are not yet defined.
Now, on to the part where the variables are defined. I used a function here which you can look up in the help manual of SCAR (to do this, just open SCAR and press F1, or click on the option “help” and then select “help” in the drop down menu), but to shorten this, I’ll just post it here:
function FindColor(var x, y: integer; Color, xs, ys, xe, ye: Integer)
So, I’ll quickly explain what to do here: x and y are the variables where the destination of the object will be saved. the “var” and “integer” are just there to show what you have to do (for the people which only look at the manual and not the tutorials on how to use the functions). Now, you probably know that every color has a number, that is why “color” is an integer, now you could define the color as a constant, but we aren’t that far yet. ;) All which is left now are the last for variables… well, good thing for you, they are easy to understand. As I told you, for SCAR the entire screen is a coordinate plane, and all those four do is say in what area you want the program to look for the color. Those can be substituted with real number. In my example it will start looking for the color on the top right corner and end at a point 100 pixels right and down. pretty easy, now isn’t it? ;)
1.2)
===Constants===
CONGRATULATIONS, you have just finished the hardest part, const are nothing compared to variables! A constant is just a given number that won't change! For example: You need to find a color, let's say the color blue. Colors are represented with numbers, (Will get to that more in detail when we get to the color chapter) and those numbers, will always be the same, so if the color number is 76854 (I made up that number, it isn't the real number of blue), it will still be 76854 when you will get to it later in the script. That easy.
Still, I think I should put in a little example:
program FindBlueColor;
const
bluecolor = 76854;
var
x,y: Integer;
begin
FindColor(x,y,bluecolor,0,0,100,100)
end.
2.1)
===Moving The Mouse Using Variables===
So, now you actually want to move the mouse and click on stuff, right? Well, that's just as easy done as said. I will teach you the very basic ones:
MoveMouse(x,y: Integer)
(Moves Mouse Instantly, not at all human-like)
MoveMouseSmooth(x,y: Integer)
(Moves Mouse at human speed(or at least that is what it is SUPPOSED to do))
MoveMouseSmoothEx(x, y: Integer; +random(0),20,40,45,25,20);
(Moves the Mouse in a human way, alosm y favorit mouse function(just keep the numbers after the x and y, don't change them)
ClickMouse(x,y: Integer; True/False: String)
(Clicks the mouse, true=Left mouse button, False= right mouse button)
Now, they can be used, but let me tell you, they are about as undetectable as having an auto responder say: “I am an Autoer! Report me!” and that about every 0.1 seconds. So, how about I’ll let you in on the functions which should be used, if you need to use mouse functions:
Mouse(var x,y: Integer; xc, yc: integer; String: Boolean);
(Now, I couldn’t find the real formula anywhere, so I just made one up, it should be about right. It moves the mouse at a declared speed to a destination. x and y are obvious, xc and yc is how many pixels the click can be away from the real x and y values {so if x is 5 and y is 6, and xc and yc are both 2, then the mouse could click anywhere from 5,6 to 7,8}, the Boolean states if left or right click, true = left, false = right).
MMouse(var x,y: Integer; xc, yc: integer);
(pretty much the same as Mouse, but it doesn’t click, only moves the mouse to given destination).
IMPORTANT: If you use Mouse or MMouse, you have to declare the speed, otherwise it will end up taking 10 minutes to cross the entire screen! The procedure is as follows: MouseSpeed := integer; (will be clearer later)
Uh oh, I just noticed a new term we didn't cover: "string". But this one is just as easy as constants. A string is a text, nothing more. So this entire thread would be just one huge string (generally speaking, there are some integers, too, but let's not be too picky), because it is a text. "true" is a string, and "false" is also a string, because it is something that is written. Another new one is Boolean, it just means true or false, that easy.
Now, it always says <name of the function>(x,y: Integer). So, what you have to do is substitute what you need. So, first of all, the thing integer is not needed, it is just there to explain that those are numbers you need to insert.
NOTE: x and y can also be substituted with normal numbers. This is pretty obvious, but I want to make sure that this is clear.
Now, remember we told the program that x and y are already numbers? So, if it fits our purpose, we can just leave them there. Now, it will recall what the "Find" function said they were supposed to be (so if the blue color was on (55,68), x and y will be (55,68) until another "find" function declares them as something else). Now let's pretend we want to use the Mouse Function and left click on the blue color. It will look something like this:
programm SecondExample;
const
bluecolor = 76854;
var
x,y: Integer;
begin
MouseSpeed := 9 (I would never use anything below 6)
FindColor(x,y,bluecolor,0,0,100,100)
Mouse(x,y,2,2,true)
end.
This is very easy, we declared the mouse speed to be 9, which is pretty reasonable. Then it finds the color in the upper left corner of the screen. If you don’t know how to find out where the coordinates are, use the color picker, or just move your mouse across the screen, SCAR will show you the coordinates. After it found the color, it saves it to x and y. After that the courser will move to the destination, with an accuracy limit of 2 pixels, and then left click. That easy :D.
3.1)
===Colors (What They Are And Their Uses)===
Um… yeah… I just realized while I edited this, I already explained colors pretty well, so guess this chapter is just review. 
Now, we touched upon colors earlier, saying that colors are represented by numbers. Every color has a certain number. You can try it out, just click on the Color Picker in your toolbar, and then on any color you want to use. It will give you the number of the color, and the x and y coordinates of the point where you clicked. Now, you need to get that thing into your script. There are two ways, first putting the number into every single function that uses this color, or give the color a name and put it under constants, so that in the future functions, you just have to re-enter the name instead the entire number of that color. The first option I only named to show both possibilities, I would always put it under constants, for then you can also read what that that color is supposed to stand for. But before we put that into a script, here are a few color finding functions:
FindColor(x, y: Integer; color, xs, ys, xe, ye: Integer)
(Searches for a color in a certain area. xs and ys is where to start (remember that it will search from the top left to bottom right), and xe and ye is where to stop searching. you color has to lie between those corner points)
_____________
|————–|
|————–|
|————–|
|————–|
|————–|
|————–|
|————–|
|————–|
|————–|
|————–|
3.2)
===Using All The Things We Learned In One Basic Script===
Go ahead and do this with me, you will understand it better and faster this way.
We start of with this:
Programm New;
begin
end.
Now we add the name, variables and constants:
programm ColorDetection;
var
x,y: Integer;
const
{<we'll add this in just a minute>}
begin
end.
Now use your color picker to pick a unique color, because remember what i said? it will stop the search after it found the first corresponding color.
After you got a color, add it into the constants
Program ColorDetection;
var
x,y: integer;
const
MovieMakerSymbol = 1686498;
begin
end.
Now add the FindColor function and mouse movements:
Program ColorDetection;
var
x,y: integer;
const
MovieMakerSymbol = 1686498;
begin
FindColor(x,y,MovieMakerSymbol,0,0,1023,767);
Mouse(x,y,2,2,true);
end.
I'll quickly explain everything again, just incase I didn't explain part of it too well:
So, we named the program we said that x and y are variables, meaning that they can represent any number, then we said that if we say MovieMakerSymbol(or whatever name and color you chose) in a place where a number is supposed to be, we mean 1686498. Then the script begins. At first it will search from the top left corner and end in the bottom right corner. It will stop the search once it found the color, and save those coordinates onto x and y. so at the moment x and y are "real numbers". Then it will move the mouse human-like to that destination, and left click on the position.
===FINISHED===
Well, now we come to the sad part: the parting. LOL. You have successfully completed the basic stages of Scar scripting, and you are now ready to learn from the masters, and no longer the "chicken" like me :P
Thanks for Reading, please leave comments. I will greatly appreciate them. :)