PDA

View Full Version : All-Proof - Looking at procedures



Daniel
09-17-2008, 07:47 AM
THE SCAR

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.

Introduction:
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.

Requirements:
The Scar - Walking Through Variables (http://www.villavu.com/forum/showthread.php?t=35494)

Contents:
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:
procedure MoveAndClick;
begin
MoveMouse(x,y);
Wait(1000);
ClickMouse(x,y,True);
end;
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);
begin
MoveMouse(x,y);
Wait(1000);
ClickMouse(x,y,True);
end;

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;.

NiCbaZ
09-17-2008, 09:00 AM
Very nice tut



<3 Freddy1990
<3 Hobbit
<3 Widget
<3 ZephyrsFury
I have 1337 standards in scripts

:o

BobboHobbo
09-17-2008, 09:36 AM
How gay is this tutorial, WHY BOTHER MAKING IT@!@!@!

















Kidding, GJ.

Daniel
09-17-2008, 09:51 AM
How gay is this tutorial, WHY BOTHER MAKING IT@!@!@!

















Kidding, GJ.
OMG, you're the gay one here.
I'm kidding too... <_> Thanks

Bonfield
09-17-2008, 10:05 AM
good tut =]

Daniel
09-17-2008, 11:26 AM
good tut =]
Thanks Bonfield :D

StrikerX
09-17-2008, 11:49 AM
How gay is this tutorial, WHY BOTHER MAKING IT@!@!@!

















Kidding, GJ.

OMFGz0rs.....Bobbo Knows Html :O

Favorited... I always start out good but i am to lazy to fix it....

Naum
09-17-2008, 11:57 AM
congratz on your tutorial cup ;)

Daniel
09-18-2008, 05:55 AM
congratz on your tutorial cup ;)
Thanks Nauman!

@strikerx25: No, he knows BBCode ;)

Da 0wner
09-18-2008, 07:07 AM
Hmm does html work?

<html>
<body>
<font color="white">Hello?</font>
</body>
</html>

Edit: Na he just knows BBCode :p.

randy marsh
09-18-2008, 09:50 AM
A bit clumpled together maybe more examples?

Daniel
09-18-2008, 10:50 AM
A bit clumpled together maybe more examples?

There are quick examples in the text ;)

:'( No one has checked out my other tutorial :p

shadohead
01-19-2009, 03:44 PM
Thanks for the help with the variables and mouse positions i might be able to incorporate this into a walking script