SRL Archive - OSR Beginner Scripting Tutorials

Programming level: Pascal!


Rezozo

2012-09-29 01:58:00

This is a guide to programming in the language: Pascal - Easy. [Currently Under Construction :) ]

*Note 1 - I suggest reading and going through this tutorial before doing most scripting, as it makes everything else easier to understand.
*Note 2 - This does not teach you how to script for RuneScape, it just teaches you the basics of pascal. This is meant to help you understand what others are talking about in scripts and tutorials, not to describe the different functions of SRL!
*Note 3 - I will be making multiple levels of this TuT, this being level Easy. This is just a glimpse into what pascal can really do!
*Note 4 - I suggest using turbo/free pascal to run these, as some common functions and decelerations are not compatible with Simba.

Lets start from the beginning. The first part of your script should include the words "Program" and the name of the program (default is new, in Simnba).

When you open up Simba, you get something like this:

program new;
begin

end.

The Begin-End is your Main Execution section. All the main things go on here ;)

Now comes the programming part:

To output text, we use the format:
Writeln(''); {put text in '', we do not use "". They are two different things} 

This would output a line. When you put Writeln, it outputs it, then puts the cursor to the next line. If you want the cursor to stay on that line, its:
Write(''); {put text in ''} 

Now normally, to inputting information is:
readln(); {put variable in () } 

However, that is not defined in Simba.

Notice how I put a Semi-Colon after each line. This signifies the end of the line, without it, it would not compile.

Variables - Variables are values that can be changed throughout the program.

To set a variable, you would use:
program new;
begin
Var
x:integer;
end.

This sets the variable X as an integer (Whole numbers including zero).

There are five main types of variables you should know: String, char, Integer, Boolean and real.

Real is the same as an Integer, but it allows division, and can contain decimals.
Boolean is a true or false value. Literally.
Char is basically a single character. Could be a number, could be a letter.
String is a set of Chars, an example is a word or a sentence.

When setting the value of a variable, you use the format:
program new;
Var
x:String;
begin
[B]x:='';[/B] {put your string in the ''}
end.

Now, taking what we learned so far, if we had to make a program which declared the variable x as a string, set it to "Hello world", then output it, It should go something like this:

program TuT;
Var
x:string;
begin
x:= 'Hello World!';
Writeln(x);
end.

You have just completed you first pascal script!


I noticed many people are having trouble and I decided to make this! I am creating this series also so no one complains anymore about not understanding what a piece does, or what is going wrong. this is meant to help all the beginners. For all you leechers out there, learn how to use pascal, it will even help you guys.

Pascal TuT for level: Medium - http://villavu.com/forum/showthread.php?p=1106362

Silentcore

2012-09-29 02:14:50

Nice guide, Hopefully people find it useful.

Rezozo

2012-09-29 02:17:31

From: Silentcore
Nice guide, Hopefully people find it useful.


I hope so as well. I get many a PM in these topics from leecherrs, as do many other members. I hope this will lessen those numbers!

Vinyl Scratch

2012-09-29 11:18:10

Great so far! I like this. Keep it up, bro!

+Repped

Rezozo

2012-09-29 12:19:26

From: Vinyl Scratch
Great so far! I like this. Keep it up, bro!

+Repped


Thanks, I hope to finally end the days of leeching with a little bit of teaching!

My rhyming skizzells are unmatched.

Rezozo

2012-09-30 00:32:03

Bumpity Bump: I just realized I forgot to add this!
If anyone has any trouble, needs an explanation, or wants me to add something. Feel free to ask! That is the reason I made this thread, that is why I am here.

zertunami

2012-09-30 13:54:04

Great job so far! I feel that you should combine your beginner and medium tuts together, it just makes more sense to me that way content-wise.

Rezozo

2012-09-30 16:32:54

From: zertunami
Great job so far! I feel that you should combine your beginner and medium tuts together, it just makes more sense to me that way content-wise.


Thank you! I really appreciate it!

I thought of combining these two, but then realized that many just want to understand or just be able to read a script, not learn it. So keeping the medium section inside the Beginners section of Tutorial Island, allows the more dedicated beginners to have a place.

Thanks for the suggestion though!

NKN

2012-09-30 16:58:46

Not bad tutorial. :)
7/10 would read again

Rezozo

2012-09-30 17:00:47

From: NKN
Not bad tutorial. :)
7/10 would read again


Thanks NKN, I appreciate it!

Im glad people like this, hopefully it will be useful in making people at least start scripting.

cadetlarouche

2012-10-01 15:26:23

Thank you very much! i want to learn to write my own scripts and if all other tutorials are easy like this, ill be a master at scripting sometime :P

Rezozo

2012-10-01 15:36:08

From: cadetlarouche
Thank you very much! i want to learn to write my own scripts and if all other tutorials are easy like this, ill be a master at scripting sometime :P


You are very welcome! If you have any questions or suggestions about this, please feel free to ask.

Swifte

2012-11-02 19:56:40

Nice TuT. But still don't get it. My brain is dead!!! Keep up the great work Rezozo and may you get SRL membership soon :)

Rezozo

2012-11-02 19:58:39

God I hope so! The script I am gonna use for the Junior Competition, will be good enough for my application!

Thanks for the compliment! If you think there is something I need to explain more, tell moi please. If you don't understand something, I am more than happy to help!

Hapayboy

2012-11-02 21:29:37

So, I'm trying to make a runescape bot, and if it can find a variable I would like it to do one thing and if it isn't able to find it do another such as if it finds it. It would continue on (example if it finds addy ore it would mine it) if it can't it would teleport and then run to where it knows where one is just in sense. Pretty much like if findcolorspiraltolerance (x,y,666666,0,0,1000,1000,15) then
movemouse (x,y)
clickmouse (x,y,1)
so to speak… if it couldn't find that then what to do as a fail safe?

ps, I'm really high don't hold it against me

Rezozo

2012-11-02 21:45:09

Lol, Definitely wont hold it against you :)

1)Im gonna explain this part:
if it can find a variable I would like it to do one thing and if it isn't able to find it do another such as if it finds it.


You cannot just check if a variable exists, it is slightly more complicated than that.
If it is an integer, then you could do:
if Variable>0 then
SomeCode;

If it is a string, you could do:

If length(string)>0 then
SomeCode;

For the example,
I'd just use direct FindObj for this:

If findobj(x, y, uptext, color, tolerance) then
Mouse(x, y, 2, 3, true);//Clicks the obj
Else
SomeThing;//FailSafe

For a Failsafe, in this situation, if you are too far and can't see that obj, make something to get closer first.
Many ways to do this. I guess you could just use a
Mouse(x, y, 5, 5, true)
to some point, giving a 5 up and down randomization.

If the object is not there currently, and you have to wait till it is, put this:

Repeat
Until(findobj(x, y, uptext, color, tolerance))

mariothecashcow

2014-09-21 08:33:57

useful beginners guide into scripting, very easy and understandable, going to read the more advanced thread and see how well I cope and soon try to apply it to a bot :D
thanks rez