Looking at Procedures
If you appreciate this tutorial, please provide the author ("Dan's The Man") with more reputation
NOTE: Do NOT attempt to use a procedure which contains MoveMouse or ClickMouse, as these will get you banned. The only purpose they're in this tutorial is for educational purposes. Please refer to other tutorials on how to implement SRL into your script for more human-like purposes.
This chapter takes you through the use and wonders of procedures. "The Scar", walks you through what to use procedures for and when. This information is vital for all scripters. If you don't know then you should read on as this is one of the steps on your way to becoming a more advanced scripter into the customized pascal language, SCAR.
1. What are procedures
2. When to use procedures
3. Setting up a basic procedure
4. Use of correct formatting
5. Receiving Errors and Fixing Them
1 - What are procedures:
Procedures are a way of doing a lot of things in the order you specify. You cannot do multiple things at once with a procedure, the same is with a function. They do not supply you with a boolean, integer, string or extended when called. Procedures need to be contained with at least 5 or more lines, they do not have to but that is the proper way of procedure formatting. As if you do, what is the point in having that procedure? You have to ask yourself that very question, as there is absolutely no point because you can just add those lines instead of writing that procedures name.
2 - When to use procedures:
If you just want part of your script to do something, multiple times, without typing the same piece of text all over again, then a procedure is right for you. Ok, so you have decided to use a procedure, but if you only need to use that procedure once, then you should get rid of it. You must put the procedure above the part of script that you're going to use it in. If you're using that procedure in multiple parts of your script then you should put that procedure at the top most part of your script that you're using that procedure in.
3 - Setting up a basic procedure:
To setup a basic procedure, you must put the word procedure, then after procedure you put the name of that procedure. You cannot name the procedure the same name as another or the name of the script, variable or constant otherwise you will receive an 'Unknown Identifier' error when running the script. After the line that the word procedure is called, you have to put a begin. The next line is what your procedure contains. In this example, i will be making a procedure call MoveAndClick. So, it will obviously move the mouse to a specified location then it will click the mouse on that spot. So, after the begin i will put MoveMouse(x,y);, if you have a basic knowledge of SCAR then you'll understand what it does. Ok, so now i will want it to click the mouse at that location, but i want it it to wait before i click the mouse so i add Wait(1000); after MoveMouse(x,y); and i want it to left click so i'll add ClickMouse(x,y,True);. I'll add an end; to end my procedure. My new procedure looks like this:
See, that will move the mouse and click the mouse at coordinates x and y. But does the person, who is using the procedure, get to set the coordinates? No, they do not because we have not allowed them to enter their own details. We want them to be able to do that so we'll add some brackets after the name which lets the person input values. This is like MoveMouse, you have brackets after the word MoveMouse which contain the letters x and y which allows you to input the coordinate. To add brackets, after the name of that procedure put an (, now that is the start of your user input area. This area is just like being able to set variables, but without using x:=100;, instead you just replace x with whatever you want, as long as it is a number. I want to put the variable name as x and the other name as y, i will put them as an integer because they're numbers. So, now my new procedure looks like this:
procedure MoveAndClick(x, y: Integer);
4 - Use of correct formatting:
Formatting, also called Standards, is what most scripters want to see in others scripts. The reason why it is mostly required is because it makes scripts more user friendly and it is better for more advanced scripters to look through the script then suggest things which are to be added or to be shortened.
Ok, to start the formatting part of the tutorial. If you have a word that is bold in your scar script, the next line should contain two or three spaces after the first bolded word, not a symbol such as ; or . but an actual word that is bolded, such as if. If there you're adding a bolded word under another bolded word, then that bolded word does not require it to have two or three spaces. Only in the next line when a word that is not bolded should receive the extra indending.
In "The Scar", the formatting tutorial is very basic as not much work has been achieved into that. So it is recommended you look at the Standards tutorial written by BamBam, it can be found in the SRL Forums: Tutorial Island section.
5 - Receiving errors and fixing them:
When you're creating your first procedure, you're most likely to get at least one error. This part of the tutorial will cover all, if not most, of the errors that will be displayed when you make a procedure.
PPP = Any Value
Unknown identifier 'PPP' in script:
This means that you have made a mistake when making brackets. For example, in my procedure i put MoveMouse(x,y); and in the brackets i put (i, p: Integer);, it is only defining i and p as an integer and not x and y. So change that PPP to the correct letter.
Type mismatch in script:
This means that you have either declared a variable as a different type than what it should be. So you probably put, in your brackets, (x, y: String);, and have MoveMouse(x, y); in your procedure. X and Y in the MoveMouse procedure are actually Integers, which require numbers. So just change the variable type, in your brackets, to Integer and you'll get that procedure working.
Semicolon (';') expected in script:
What this error means is that you have not put a semicolon, ;, to where it should be. You need to put a semicolon after the brackets or the procedure name. An example of this error would be: procedure ClickAndMove, see how there is no semicolon. To simply fix this error, add a semicolon after the name, like this (The fix is underlined): procedure ClickAndMove;.