PDA

View Full Version : THE Beginner's Simba Tutorial



Pages : [1] 2

Coh3n
09-13-2010, 04:08 AM
THE Beginner's Tutorial
This tutorial was last updated on September 23rd, 2012.

Introduction

Hello, and welcome to the first of three of my all-in-one scripting tutorials. This is a rewrite of the beginner's section of my All-In-One SCAR Scripting Tutorial (http://villavu.com/forum/showthread.php?t=49089). Throughout this tutorial, you will learn many different scripting techniques, commands, and habits I’ve picked up during my time here at SRL.

As well as learning how to script in Simba, you will be learning the programming basics which will help you learn other, more complicated programming languages such as Java, Python or C/C++ (there are many more). Simba allows programming in the Pascal programming language (http://en.wikipedia.org/wiki/Pascal_(programming_language)) so naturally, that is the language I'll be teaching you.

I will be taking you through the different concepts step by step, starting with the basics. Keep in mind that no prior programming knowledge is required for you to understand this guide (but of course, it would be helpful).

Before continuing through this guide, you need to make sure you have installed Simba and SRL properly. If you don't know how to do this, you can follow this tutorial to do so -> How to install/setup Simba! (http://villavu.com/forum/showthread.php?t=47714) This is very important: I highly suggest that as you read this tutorial, you do the examples as they are taught to you. This way you will have a much better understanding of the concept. :)

I would also like you to please post any spelling/grammar/formatting mistakes I will probably make somewhere throughout the guide. If you want, this tutorial can be downloaded as a PDF, new link coming soon


Table of Contents

Simba - The Basics

Knowing Simba
The Basic Types
Procedures and Functions
Constants and Variables
Putting it all Together

Standards
Scripting Tips/Hints

Codehints/Simba Library
Simba and SRL Documentation
HotKeys
The "Tab" Button

Programming Statements

If..Then..Else Statements
Cases
Loops

Repeat..Until
While..Do
For..To..Do
Internal Commands

Try..Except..Finally Statements
Putting it all Together

The SRL Include
DeclarePlayers & S.M.A.R.T.
Failsafes
Antiban and AntiRandoms
Conclusion


Simba - The Basics

Knowing Simba

When you open Simba, you will notice a blank script that looks like this:

program new;
begin
end.


The program New; part is what your script will be called. The program can be changed to whatever fits your interest. For example, you could change it to "Bobs_Amazing_Woodcutter" or "JoesMiner". Notice the "_" used instead of " ", this is because in any programming language, there cannot be spaces in names. This includes the names of procedures and functions (more on that later).


The begin..end. is called your Main Loop. Simba will read the code in your main loop as your script and run is as you please. If you would like Simba to run a function or procedure, you have to include them in your main loop. More on script structure later.


Over on the left, you have the Functions List. You'll notice that there's several categories to choose from. These are all the built-in Simba functions that you can use at any time you wish.


Just below the Functions List, you have the Library Search Bar. In my opinion, this is one of the most useful Simba features as it allows you to search for any function/procedure that you wish. Type in "Color" (without quotes), and watch as it narrows the list down to only the functions/procedures that contain the word "Color".


At the bottom of the window you'll see a white box with some writing in it. This is called the Debug Box. Any errors you may have with yours or someone else's script, will come up in this box.


Here is an image to better explain the Simba components.


http://i.imgur.com/5HVIOQL.png



The Basic Types

This was taken straight out of the SCAR (http://freddy1990.com/index.php?page=product&name=scar) Manual, I couldn't have explained it better myself.


http://i.imgur.com/nKzAIuB.png


Procedures and Functions

Procedures (http://en.wikipedia.org/wiki/Procedure_(term)) and functions (http://en.wikipedia.org/wiki/Function_(computer_science)) are similar, yet different. Functions return a specified type such as a boolean or an integer whereas a procedure doesn't return any type, it just does what it's told.


To start off, I am going to explain to you the structure of functions and procedures using the following example:

function IntToStr(i: LongInt): String;


The function part is where it determines whether a function or a procedure is going to be used. If a procedure was going to be used, it would take place of "function"..


Following function, is the name of the procedure/function. In this case, the name is "IntToStr", which stands for Integer To String, and simply converts an integer to a string. The name can be anything you want, as long as it contains no spaces (like the program name).


Inside the parentheses, we have the parameters of the procedure/function. In this example, there is one parameter, i. As you can see, i is declared as a LongInt, which is the same thing as an integer.


Following the closed brackets is the Result of the function. In this case, the result is a string. However, the result can be whatever fits your needs (i.e. String, Integer, Boolean). Remember that this part is always left out of procedures. When I say "Result", I mean the undeclared variable (http://en.wikipedia.org/wiki/Variable_(programming)) that needs to be used somewhere in the function.



The WriteLn procedure is a very useful procedure that can tell you why your script worked or why it didn't work. It is used a lot in a process called "Debugging" which simply means - removing all the bugs from your script so everything works well. All this procedure does is write the string (s) to the debug box.

procedure WriteLn(s: String);


Try this:

program HelloWorld;

procedure WriteInDebugBox;
begin
WriteLn('Hello world!'); // Notice the ';' at the end of the line; make sure you have that at the end of each line, otherwise you will most likely get an error
end;
// Notice the ';' This must be at the end of every procedure/function in your script
// Only the "end" in your main loop should be followed by a '.' to signal the end of the the script

begin
WriteInDebugBox; // See how I call the procedure in my main loop? Without this step, the script wouldn't do anything
end.


Now when you hit run (the green play button at the top of Simba), do you see the "Hello world!" in the debug box? That is probably one of the simplest scripts you're going to see. You can change "Hello world!" to anything that you want to see in the debug box.


Try this:

program HelloWorldFunction;

function GetNumber: Integer;
begin
Result := 10; // Because the function returns an integer, there is a variable "Result" that needs to be used; it needs to be set to an integer
end;

begin
WriteLn(IntToStr(GetNumber)); // Because Result is an integer, and WriteLn requires a string, we use IntToStr
end.


Now when you hit run, you should see "10" in the debug box. Do you see the difference between a procedure and a function? It may not seem like much of a difference now, but once you get into more advanced scripting techniques, it will make a huge difference in your script.


Constants and Variables:

Constants (http://en.wikipedia.org/wiki/Constant_(programming)) are usually declared at the beginning of your script, and remain constant throughout your whole script. They are declared like this, and can be used in any procedure/function throughout your script:

program new;

// Constants should be in ALL_CAPITALS to easily distinguish what's a constant and what's a variable
const
LOGS = 100;

begin
end.

Pretty simple I'd say. :)


Variables (http://en.wikipedia.org/wiki/Variable_(programming)) can be declared in two different ways:



Globally - means you would declare it at the top of your script, and can be used throughout all procedures/functions. It can also be reset at any time.
Locally - means you would declare it inside a procedure/function and would only use it for that procedure/function. It can only be reset in the function/procedure it was declared in.


program Variables;

// Globally, should start with a capital letter then "camel-capped"
var
NumberOfLogs: Integer;

// Locally, should start with a lowercase letter then "camel-capped"
function WriteInDebugBox: Integer;
var
b: Boolean;
begin
// I can use "b" in this function only
// I can use "NumberOfLogs" in this function as well as other functions/procedures
end;

procedure SayHello;
begin
// I can use "NumberOfLogs" in this procedure as well as in the above function
end;

begin
end.

Not too hard, is it?


Putting it all Together

Now that you've learned the absolute basics, we are going to make a small script, tying everything together. You'll also learn a few new useful commands in the process.

program PuttingTogetherBasics;

// Declareing variables globally
var
Logs: Integer;
Exps: Extended;

// Declareing constants
const
NUMBER_OF_LOGS = 500; // Notice the integer
TREE_TO_CUT = 'Magic'; // Notice the string

// Using a procedure
procedure HowManyLogs;
begin
// This is how we ASSIGN a type to a variable; Remember this ;)
Logs := 250; // Notice we can use the variable "Logs" because it's declared globally
Exps := 195.5;

WriteLn('We have chopped ' + IntToStr(Logs) + ' logs this session!'); // Notice the '+', this is required if you are going to WriteLn a constant or variable
Wait(500); // This is new, but don't worry; this is a simple procedure that waits the given time in milliseconds (1000ms = 1s)
WriteLn('We want to chop ' + IntToStr(NUMBER_OF_LOGS) + ' logs.');
Wait(500);
WriteLn('We are chopping ' + TREE_TO_CUT + ' trees!');
Wait(500);
WriteLn('We have gained ' + FloatToStr(Logs * Exps) + ' xp this session!');
//FloatToStr is used to convert extended values to strings; it works the same as IntToStr
end;

// Using a function
function WeAreBored: string;
var // Declareing variables locally
s: String;
begin
Result := 'What are we going to do now?'; // Notice that "Result" is a string because the function returns a string
s := 'We are very bored chopping all these logs!';
Wait(500);
WriteLn(s); // Notice no "IntToStr" because the variable "s" is already a string
end;

begin // Don't forget to put your procedures/functions in the main loop!
ClearDebug; // This procedure just clears the debug box when you click run
HowManyLogs;
WriteLn(WeAreBored); // Since WeAreBored returns a string and WriteLn() takes a string as its parameters, the function itself can be called
end. //Notice the '.', signalling the end of the script

If there is something about that script that you don't understand, don't panic! Try looking back over the section you don't understand.


You may ask what the point of a function like this would be. Well, this function could be used if you were going to make a progress report for your script. A progress report is something that is usually added to every script that keeps track of what the script has done. For example, how many logs it has chopped, or how many fish it has caught. Here are a couple example of progress reports in scripts I've made in the past.

[================================================== ===============]
[ Coh3n's Draynor Chop N' Bank! ]
[============================ Rev.32 =============================]
[ ]
[ Ran For: 85 Hours, 28 Minutes and 38 Seconds ]
[ ]
[ Nick T/F Loads Logs Lvls Exp. Brks ]
[ ¯¯¯¯ ¯¯¯ ¯¯¯¯¯ ¯¯¯¯ ¯¯¯¯ ¯¯¯¯ ¯¯¯¯ ]
[ WC01 T 118 3302 14 222884 19 ]
[ WC02 T 115 3220 3 217350 17 ]
[ WC03 T 114 3192 3 215460 17 ]
[ WC04 T 110 3080 3 207900 17 ]
[ WC05 T 107 2995 6 202162 16 ]
[ WC06 T 96 2688 3 181440 15 ]
[ WC07 T 91 2548 10 171990 13 ]
[ WC08 T 107 2996 11 202230 16 ]
[ WC09 T 88 2463 7 166252 15 ]
[ WC10 T 82 2295 7 154912 13 ]
[ WC11 T 66 1848 5 124740 11 ]
[ WC12 T 65 1820 8 122850 12 ]
[ WC13 T 76 2127 6 143572 13 ]
[ ]
[================================================== ===============]

/================================================== ===================================|
| Coh3n's Draynor Chop N' Bank! |
| - Revision 40 - |
|================================================= ====================================|
| |
| Ran For: 34 Hours, 8 Minutes and 49 Seconds |
| Program: SCAR | SMART: Yes |
|______ ________ __________ _______ ________ __________ ________ ____________ ________|
|Alias | Active | Location | Loads | Tree | Logs Cut | Levels | Experience | Breaks |
|¯¯¯¯¯¯ ¯¯¯¯¯¯¯¯ ¯¯¯¯¯¯¯¯¯¯ ¯¯¯¯¯¯¯ ¯¯¯¯¯¯¯¯ ¯¯¯¯¯¯¯¯¯¯ ¯¯¯¯¯¯¯¯ ¯¯¯¯¯¯¯¯¯¯¯¯ ¯¯¯¯¯¯¯¯|
| WC01 | True | Bank | 49 | Willow | 1,372 | 7 | 92,610 | 5 |
| WC02 | True | Bank | 43 | Willow | 1,204 | 2 | 81,270 | 4 |
| WC03 | True | Bank | 27 | Willow | 756 | 73 | 51,030 | 3 |
| WC04 | True | Willows | 59 | Willow | 1,652 | 73 | 111,510 | 6 |
| WC05 | True | Bank | 52 | Willow | 1,456 | 2 | 98,280 | 6 |
| WC06 | True | Bank | 43 | Willow | 1,204 | 3 | 81,270 | 3 |
| WC07 | True | Bank | 31 | Willow | 868 | 6 | 58,590 | 3 |
| WC08 | True | Willows | 22 | Willow | 616 | 1 | 41,580 | 1 |
| WC09 | True | Bank | 13 | Willow | 364 | 0 | 24,570 | 0 |
| WC10 | True | Willows | 29 | Willow | 809 | 0 | 54,608 | 3 |
| WC11 | True | Bank | 40 | Willow | 1,120 | 65 | 75,600 | 3 |
| WC12 | True | Bank | 51 | Willow | 1,428 | 2 | 96,390 | 5 |
| WC13 | True | Bank | 32 | Willow | 896 | 1 | 60,480 | 3 |
|-------------------------------------------------------------------------------------|
| Totals: | 491 | | 13,745 | 235 | 927,788 | 45 |
|_________________________________________________ ____________________________________|
|_________________________________________________ ____________________________________/


If you successfully made the latter script, when you hit run, your debug box should say this:
We have chopped 250 logs this session!
We want to chop 500 logs.
We are chopping Magic trees!
We have gained 48875 xp this session!
We are very bored chopping all these logs!
What are we going to do now?
Successfully executed


Congratulations! You have just made your first working script! Yay! :D



Standards

A simple definition of standards is the way you write your code. Having good standards is extremely useful for debugging and readability. Anyone that reads your script will thank you for having good standards. I urge you to develop good standards as soon as you start scripting, so you get used to it faster, and don't have to change the way you code later.

There are many different rules you should follow when writing your code. They are as follows:

When you indent, it will be two spaces. You can do this by hitting the "Tab" button on your keyboard, or simply hitting the space bar twice.


Your script margins are set to 80 characters and is marked in Simba with a line straight down the right side of the scripting page. Try not to exceed that margin. If you do, no big deal, no one's going to kill you for it. ;)


The begin statement appears on its own line, and end statement always matches the begin statement by columns. For example:

begin
if (Condition) then // Notice the intent after a "begin" statement
begin // Notice how the begin lines up with "if" in columns
DoThis;
end else
begin
DoThis;
end;
end;

Notice how all the begins and ends line up in columns. Also, you're probably wondering what the "if (Condition) then" is. Well, don't panic, it's called an if..then..else statement, and you'll learn more on that later. But, notice how the begin after the if statement is lined up with "if" in columns. Most people make the mistake of indenting the "begin" after an if statement, which makes their code harder to read.


Use semicolons at the end of all your lines. Exceptions would be at the end of var, begin, then, else, repeat, do and before else (see the above example if you don't know what I mean).


Try not to combine two or more statements on one line. Each statement gets it's own line.

// Bad
if (Condition) then DoThis;
if (Condition) then begin DoThis; DoThat; end;

// Good
if (Condition) then
DoThis;

if (Condition) then
begin
DoThis;
DoThat;
end;


Always use spaces after commas and arithmetical signs. This is also a common mistake with most scripts, and it really bugs me when people don't do this. It makes the script much harder to read without the spaces. Here is an example:

// Bad
i:=(5*4+3);
HowManyLogs(1,5,10);

// Good
i := (5 * 4 + 3);
HowManyLogs(1, 5, 10);


You should never have a white space on the inside of parenthesis. Example:

// Bad
if ( i = 100 ) or ( k = 50 ) then
DoThis( DoThat );

// Good
if (i = 100) or (k = 50) then
DoThis(DoThat);


Simba bolds keywords such as "begin, end, procedure, function, etc." These words should be entirely lowercase as it looks much better, and a lot of people find it easier to read. :)


The names of procedures and functions should always begin with a capital letter and be camel-capped (i.e. Pascal case (http://msdn.microsoft.com/en-us/library/x2dbyw72%28v=vs.71%29.aspx)) for easier readability. Example:

// Bad
procedure walktobank;

// Good
procedure WalkToBank;


The names of procedures/functions/variables/constants should be given names meaningful to their content. A name like DoStuff is not meaningful, but name WalkToBank is. This includes a function's parameters.


The layout of programming components should be easily distinguishable between one another.



Constants should be entirely uppercase.

LOGS_NORMAL = 0;
LOGS_OAK = 1;

Global variables should start with an uppercase letter and then camel-capped (Pascal case (http://msdn.microsoft.com/en-us/library/x2dbyw72%28v=vs.71%29.aspx)). This should also be the same for a function's/procedure's parameters (excluding single lettered parameters).

var
TotalLogs: Integer;
WhichTree: string;

Local variables should start with a lowercase letter and then camel-capped (Camel case (http://msdn.microsoft.com/en-us/library/x2dbyw72%28v=vs.71%29.aspx)).

procedure Example;
var
i: Integer;
tempString: string;
begin
end;


You may not like the look of some of these, so you don't have to use them. There are some programming languages out there that have forced standards. Thankfully, you don't have to worry about that as Pascal has no such thing.


Where possible, parameters/variables of the same type should be combined into one statement. For example:

// Bad
var
Logs: Integer;
Ores: Integer;
Fish: Integer;

function WalkToBank(i: Integer; j: Integer; l: string; k: string): Boolean;

// Good
var
Logs, Ores, Fish: Integer;

function WalkToBank(i, j: Integer; l, s: String): Boolean;


Boolean variable names must be descriptive enough so that their meanings of True and False values will be clear.

// Bad
var
b: Boolean;

// Good
var
DoesBank: Boolean;



When you declare a variable, they are put on the next line after the var statement, and are indented. Example:

// Bad
var Logs: Integer;

// Good
var
Logs: Integer;


Try to declare variables locally as much as possible to avoid confusion within the script.


The use of white space is highly suggested. It makes your code look neater, it's more readable, and in general I find it to be a good habit. Also, the readers of your script will appreciate it. If you don't know what I mean, don't worry, I'll be pointing out the use of white space as the tutorial goes on.


There, you should now have a good knowledge of Simba standards, and have no excuses for unreadable code. :D



Scripting Tips/Hints

In this section of the tutorial, you will learn independent ways of answering your scripting questions, so you don't have to post on the forums. You will also learn how to utilize Simba so that you can script faster and more efficient.

Codehints/Simba Library

In addition to the functions list/library search to the left of your Simba window, we also have codehints and a list of every programming component built into Simba.


When you open Simba, click the mouse on a blank line and hit Ctrl + Space. A list of EVERY available function, constant, variable, type, etc. will pop up. These are all the programming components you have at your disposal.


http://i.imgur.com/FPBchD4.png


You'll probably notice that the list is extremely long, and it would take forever to scroll through, examining each part. So, as you start typing something, the list will get smaller and only show the functions/procedures that begin with what you typed. Try it yourself. ;)


Another thing you may be unsure of is just what a function's or procedure's parameter's are. There is also a built in feature for this. Click on any function in the function's list to the left. At the bottom of the Simba window, you should see the function name with all it's parameters.


http://i.imgur.com/mAyjMvU.png

You've probably noticed this already, but if you type out the function once you hit the opening bracket, a small window should come up, showing the parameters.


http://i.imgur.com/FW7nYM1.png


Simba and SRL Documentation

The Simba Documentation (http://docs.villavu.com/simba/) is useful for everything Simba related. You don't know exactly what a built-in function does? No problem, just head over to the Simba Documentation and navigate through the menus to where you want to be.


The SRL Documentation is exactly the same as the Simba documentation, except for SRL, obviously. A lot of functions include examples and explanations, so if you want to know how something works, check out the SRL Documentation (http://docs.villavu.com/srl-5/).


Hotkeys

Hotkeys are very simple to understand. They are just keyboard shortcuts that allow you to do certain things in Simba. Here is a list of the most useful hotkeys.



Run -> F9
Stop -> F2
Add Tab -> Ctrl + T
Save -> Ctrl + S
Library -> Ctrl + Space
Undo -> Ctrl + Z
Redo -> Ctrl + Y



That is just a list of the most useful hotkeys. To find out what other hotkeys Simba has, just look through the different pull-down menus. By pull-down menus I mean:


http://i27.tinypic.com/22ku8l.jpg


The "Tab" Button

As you continue scripting, the tab button will become your best friend. It allows you to move multiple lines of code incredibly fast. You can move 100s of lines forward or backwards as many lines as you wish.


Nothing feels worse than when you need to move 300 lines of code ahead 2 spaces and you hit the space bar twice at every line. Say I want to move this code ahead two spaces to squire proper standards:

procedure HelloWorld;
begin
WriteLn('Hello world!');
Wait(500);
WriteLn('How is the world doing today?');
Wait(500);
end;

I would highlight the code in between the begin..end nest and hit Tab. My code now looks like this:

procedure HelloWorld;
begin
WriteLn('Hello world!');
Wait(500);
WriteLn('How is the world doing today?');
Wait(500);
end;


See? Doesn't that look much better? :) Now, Tab moves the code ahead two spaces, but what if you want to move your code back two spaces? Well, this can be achieved by highlighting the code you want to move, and hitting Shift + Tab. Try it yourself.

Just use these simple tips and you'll learn more, faster. Again, only post on the forums as a last resort. You learn much more if you look for things yourself! For a little more in-depth tutorial on scripting shortcuts see -> Not-so-well known SCAR shortcuts (http://www.villavu.com/forum/showthread.php?t=46764&highlight=scripting+shortcuts) (yes, it's for SCAR, so not everything will work in Simba).



Programming Statements

There are many many programming statements out there. In this section of the tutorial, I will teach you the most important ones. With these statements, you'll be able to make almost any kind of script. :)

If..Then..Else Statements

If..Then..Else statements (if statements for short) are what make scripts, scripts. They can perform checks to make sure the script is doing what it's suppose to do, and if it's on the wrong course, do something else to correct the course. Here is a small breakdown of the statement:

// Notice the () around Condition, you should always use brackets in if statements for readability
if (Condition) then // Condition can be any variable check, i.e. boolean, integer, string, extended
begin // Notice the 'begin' after the 'if..then'; this is ALWAYS needed if you are going to perform more than 1 action
Action1;
Action2;
end else // 'end' ends Action1/Action2; 'else' means it will do Action3/Action4 IF the Condition is not true
begin
Action3;
Action4;
end;

if (Condition) then
Action1 // Notice there is no ';' and no 'begin'; neither is needed if you are performing ONLY 1 action after an if statement. If you put a ';' it will result in an "Identifier expected" error
else // Notice that there's no 'end', that's because there's no 'begin' we have to end
Action2;


Now that is a pretty simple example, but you should understand how to write an if statement. Here is a little more complicated example that actually does something:

program IfThenExample;

procedure RandomFunction;
var
i: Integer;
begin
if (Random(10) < 5) then // Random(10) will generate a random number between 0-9
WriteLn('Less than 5!') // Remember, no semicolon and no begin..end!
else
WriteLn('Greater than or equal to 5!');

i := Random(1000); // See how I assinged i to a random integer between 0 and 999
if ((i < 100) or (i > 500)) then // Will execute if either statement is true
begin
WriteLn('Small or large!'); // See how there's begin..end nests when there's more than one action?
WriteLn('Which is it?');
end else
begin
WriteLn('Somewhere in the middle!');
WriteLn('But where...?');
end;
end;

begin
ClearDebug;
RandomFunction;
end.


I know that looks like a lot, but examine it line by line. If some part of that is confusing, just look back over that section of the tutorial, or break down the script into sections. If you successfully wrote this script, when you press run, your debug box should read something like:
Greater than or equal to 5!
Somewhere in the middle!
But where...?
Successfully executed.
There, it's not so hard, is it? Try playing around with the variables to get a visual of what exactly if statements do. You now fully understand what an if statement is and how to use them! :)


Cases

Cases are used for a more efficient way of writing long and confusing code. Here is a simple breakdown of a case:

// Notice the layout I have for a case; this ensures readability and organization
case Condition of // Like if statements, Condition can be any variable
Option1:
begin // Notice the begin..end nest for more than 1 action
Action1;
Action2;
end;

Option2:
Action3; // Notice a begin..end nest is not needed because it is only one action
else
Action4; // If there is not an option, it will perform Action4
end;

// Notice the white space (remember from earlier?) between the options

Shouldn't be too difficult to understand. :)


Here is an example of the long and confusing code I was talking about. Be sure to not skip over this little bit as there is something new in the script. :p

// Notice the white spaces I use inbetween statements
procedure WhichSport(Sport: string); // Notice the parameter I added so I can call different "Sports" later on
begin
if Lowercase(Sport) = 'hockey' then
WriteLn('The sport is ' + Sport);

if Lowercase(Sport) = 'soccer' then
WriteLn('The sport is ' + Sport);

if Lowercase(Sport) = 'basketball' then
WriteLn('The sport is ' + Sport);

if Lowercase(Sport) = 'baseball' then
WriteLn('The sport is ' + Sport);

if Lowercase(Sport) = 'rugby' then
WriteLn('The sport is ' + Sport);

if Lowercase(Sport) = 'football' then
WriteLn('The sport is ' + Sport);
end;

begin
WhichSport('Hockey'); //Notice how I called the procedure with the parameter I made; it can be whichever sport you want
end.


You are probably wondering what "Lowercase" is. Well...


function Lowercase(s: string): string;
Returns the specified string in lowercase.

This means that if you set the Sport parameter as 'hOcKeY', it will still recognize it as 'hockey'. This is handy to use in parts of your script that other people will fill out, such as DeclarePlayers(more on that later), because no matter how they write it, the script will still run as it should.


Now, the above script is not very pretty is it? It's also very difficult to read. So, we use a case, which would make the procedure look like this:

program CaseExample;

// Again, notice the white spaces
procedure WhichSport(Sport: String);
begin
case Lowercase(Sport) of
'hockey':
WriteLn('HOCKEY!');

'soccer':
WriteLn('SOCCER!');

'basketball':
WriteLn('BASKETBALL!');

'baseball':
WriteLn('BASEBALL');

'rugby':
WriteLn('RUGBY!');

'football':
WriteLn('FOOTBALL!');

else
WriteLn('Sport is not in the selection!');
end;
end;

begin
ClearDebug;
WhichSport('HoCkEy'); // Notice how I spelled "hockey" with capital letters, it is still recognized as "hockey"
end.


Using a case not only makes your code look better, but it shortens it up quite a bit. I suggest playing with the variable Sport, so you get a better understanding of cases. Now, if you successfully made that script, when you hit run, the debug box should read:

Successfully compiled (4 ms)
HOCKEY!
Successfully executed.

Congratulations! You now know how to use a case to make your code shorter, more efficient, and and look better!


Loops

Using loops effectively can make or break a script, whether it is for RuneScape or any other program. I'm going to be teaching you three different kind of programming loops:



Repeat..Until
While..Do
For..To..Do


It shouldn't be too hard to guess what each loop does, just by their name, but if you still have no idea, don't worry... just read on. :p


Repeat..Until



Repeat..Until loops are the easiest loop to understand and use. They will be used many times throughout your scripts. What it does is pretty straight forward - it repeats an action until it is told to stop. Simple as that. Here is a simple breakdown of the repeat..until loop:

repeat // The 'repeat' acts like a 'begin', so 'begin' isn't necessary here
Action1; // You can have as many actions here as you wish
Action2;
until(Condition(s));
// The 'until' acts like an 'end', 'end' isn't necessary
// You can have more than one Condition; each condition is usually separated by 'and'/'or'


Here is a nice, simple example that clearly shows what a repeat..until loop is all about:

program RepeatUntilExample;

// Can you spot when the loop will stop?
procedure RepeatExample;
var
numberOfWaits: Integer;
begin // Although 'repeat' acts like a 'begin', 'begin' is still needed here to signal the start of the procedure
repeat
Wait(500);
Inc(numberOfWaits); // The Inc() command simply increases the var numberOfWaits by 1
WriteLn('We have waited ' + IntToStr(numberOfWaits) + ' times');
until(numberOfWaits = 5);
end;

begin
ClearDebug;
RepeatExample;
end.


Pretty simple, no? The more you script, the more uses you will find for these loops, and the better you will get with them. If you successfully made the above script, your debug box should look something like this:
We have waited 1 times.
We have waited 2 times.
We have waited 3 times.
We have waited 4 times.
We have waited 5 times.
Successfully executed
Congratulations, you have learned what repeat..until loop is, and how to use it! An example of the usage of this loop is when opening a bank. You can repeatedly try to open the bank until your character has logged out, or it has tried more than 10 times.



While..Do



While..Do loops act almost exactly the same as repeat..until loops, only they are set up differently. The difference is that repeat..until loops will execute the command at least once, no matter what, whereas a while..do loop may not execute the command at all. To be honest, it doesn't really matter which one you use. There are certain situations where it would be better to use one or the other as you'll discover the more you script. Here is a simple breakdown of the loop:

while Opposite(Condition) do // For a while..do loop, you have to set the Condition to the OPPOSITE of what you want
begin // Again, notice the begin/end for more than one action
Action1;
Action2;
end;

while Opposite(Condition) do
Action1; // Again, since it's only one Action, no begin..end nest is needed


Here is an easy example, that should clearly show you how to use a while..do loop.

program WhileDoExample;

procedure WhileDoExample;
var
count: Integer;
begin
while (Count <> 5) do // See how the condition is the opposite of what you want? You want the script to end when Count = 5, so while Count doesn't equal 5, do this (<> means "doesn't equal")
begin
Inc(Count);
Wait(500);
WriteLn('The count is ' + IntToStr(Count) + '.');
end;
end;

begin
ClearDebug;
WhileDoExample;
end.


In my opinion, a while..do loop is slightly more advanced than a repeat..until loop, simply because it is a little shorter, and requires some thinking to come up with the opposite condition. If you wrote the above example properly, when you press run, your debug box should look like this:
Successfully compiled (48 ms)
The count is 1.
The count is 2.
The count is 3.
The count is 4.
The count is 5.
Successfully executed
Well there you go, you now know how to effectively use a while..do loop. A while..do loop is most commonly used in scripts that require some waiting while the character is doing something such as chopping down a tree or fishing.



For..To..Do



For..To..Do loops are the most complicated of the three loops, and can be used in the simplest functions, as well as the most advanced functions. Here is a simple breakdown of the loop:

for (var Assignment/Start Integer) to (Finish Integer) do // For..To..Do loops increase the variable integer by one each time through the loop
begin
Action1;
Action2;
end;

for (var Assignment/Start Integer) to (Finish Integer) do
Action1;


Confused? If so, examining the following example should clear things up for you.

program ForToDoExample;

procedure ForToDoExample;
var
i: Integer;
begin
for i := 0 to 5 do // Notice the assignment mentioned earlier? The assignment is the ":="
begin
Wait(500);
WriteLn('The variable i = ' + IntToStr(i));
end;
end;

begin
ClearDebug;
ForToDoExample;
end.


The same type of procedure can be written using both repeat..until and while..do loops. However, for..to..do loops are much more advanced and makes for a faster script. If you managed to understand for..to..do loops, you are well on your way to becoming an awesome scripter. Successfully writing the above script results in the debug box looking like this:
The variable i = 0
The variable i = 1
The variable i = 2
The variable i = 3
The variable i = 4
The variable i = 5
Successfully executed
If you made it through that, well done! If not, re-read the parts you don't understand because there is no point in moving on to more advanced material if you don't understand the basics. Remember to take things slowly and not to get frustrated!



Internal Commands




It is important to remember, that with ALL LOOPS, they will continue till they are done if they are not told to stop. That is why they are called Loops, they repeat.


Thanks Nava for that awesome little explanation. Now, there will be times that a condition is met or not met and you want the loop to break, continue, or exit, hence the three internal loop commands:



The Break; command is probably the command you will be using most as when it is called, it "breaks" out of the loop and continues with the rest of the procedure or function.


Continue; is a useful command when used properly. When called, it stops the loop where it is and continues from the beginning of the loop. It's important to remember that is doesn't start the loop over, it continues. Say you wanted to repeat a loop 10 times. If on the fifth cycle through you called Continue, it wouldn't start back at one, it would start at 6. Understand?


Exit; is most commonly used in loops, but can be used otherwise. When called, Exit exits out of the loop and the procedure/function, and continues along with the script. It is used a lot for failsafes (more on that later). Say you have a function that's suppose to find an item in the inventory. But if the inventory isn't open, it won't work. Therefore you can call Exit; if the inventory isn't open so it won't try to find the item when it already knows it wont.



These commands are especially useful because they prevent the cause of what we call infinite (endless) loops (http://en.wikipedia.org/wiki/Infinite_loop). Nothing looks more like autoing then when your character is standing in the same place repeating the same thing over and over again, accomplishing nothing. Here is an example of an infinite loop:

program InfiniteLoops;

(**
* Notice that it will never stop printing "Waiting..." to the debug box every
* second because i is never reset, it is ALWAYS equal to 5. This is an example
* of what NOT to do :p
*)
procedure InfiniteLoopExample;
var
i: Integer;
begin
i := 5;
while (i = 5) do // while i equals 5
begin
WriteLn('Waiting...');
Wait(1000);
end;
end;

begin
ClearDebug;
InfiniteLoopExample;
end.

You'll notice that "Waiting..." will repeatedly print to the debug box until you manually execute the script. Do you know what an endless loop does? Thought so, it's pretty straight forward. :)


Here's an example that uses each type of loop and each type of internal command.

program InternalCommandsExample;

function RepeatUntil: Boolean;
var
count: Integer;
begin
repeat
if (Random(100) > 75) then
begin
WriteLn('Greater than 75!');
Exit; // See how it will exit if the random number is greater than 75?
end else
WriteLn('Less than or equil to 75!');

Inc(count);
until(count = 10); // If no number is greater than 75, it will repeat 10 times
end;

procedure ForToDo;
var
count: Integer;
begin
for count := 1 to 10 do
begin
if (count = 5) then
Continue; // You'll notice that when count equals 5, nothing gets written to the debug box

WriteLn('Count does not equal 5! Count = ' + IntToStr(count));
end;
end;

procedure WhileDo;
var
count: Integer;
begin
while (count < 100) do
begin
if (count >= 10) then
Break; // See how it will break out of the loop if the count is greater than or equal to 10?

WriteLn('Count is less than 10!'); // This will not be written if count is greater than or equal to 10 because we broke out of the loop
Inc(count); // Can't forget this, otherwise we'll have an infinite loop; take it out and run the script
end;
end;

begin
ClearDebug;
RepeatUntil;
ForToDo;
WhileDo;
end.


Not too difficult I hope. Do you have better understanding of the internal commands? Good. You'll find that these are essential in making a well working script and when forgotten may mean the difference of a 5 minute runtime as opposed to 5 hours.


When you run the above script, your debug will read something like this:

Less than or equil to 75!
Greater than 75!
Count does not equal 5! Count = 1
Count does not equal 5! Count = 2
Count does not equal 5! Count = 3
Count does not equal 5! Count = 4 // Notice here how there's no 5 written?
Count does not equal 5! Count = 6 // This is because we told the loop to continue when the count was 5
Count does not equal 5! Count = 7
Count does not equal 5! Count = 8
Count does not equal 5! Count = 9
Count does not equal 5! Count = 10
Count is less than 10!
Count is less than 10!
Count is less than 10!
Count is less than 10!
Count is less than 10!
Count is less than 10!
Count is less than 10!
Count is less than 10!
Count is less than 10!
Count is less than 10!
Successfully executed.


Well there you go, all the information you need to know about the three loops! If you understood everything I just showed you, I shouldn't see any infinite loops in any scripts! :D


Try..Except..Finally Statements

These statements are probably the most difficult to understand. Like the rest, there is a time and place to use them. You'll find that there aren't many situations where they can be used, but they are extremely useful when you do.


Try..Except statements are used so that if your script were to encounter a runtime error (an error that happens while the script is running), it wouldn't stop, but continue on. The best example of this would be when reading a file. If you told Simba to read from a file that doesn't exist, you would get a runtime error and the script would stop. However, if you used a try..except..finally statement, the script wouldn't stop, it would continue on, but without the information that was supposed to be obtained from the file.


I hope that wasn't too confusing for you. There are three different ways you can write try statements. Here's a breakdown of each:

// 1.
try // Like a repeat loop, 'try' acts as a 'begin'
Action1;
Action2; // Again, there can be as many actions as you wish
except // Short for 'exception'
Action3;
Action4; // If the script encounters an error in Action1/2, it will run Action3/4
end; // This is required no matter which way you write the statement

// 2.
try
Action1;
Action2;
finally // This will execute Action3/4 NO MATTER WHAT, even if Action1/2 was an Exit; command
Action3;
Action4;
end;

// 3.
try // What to attempt to do
Action1;
Action2;
except // What to do when it encounters an error
Action3;
Action4;
finally // What to do no matter what
Action5;
Action6;
end;


I'm sure you get the idea, but here's a short example that uses the third way of writing it. Read this one carefully because it teaches you how to write from a text file. :)

program TryExceptFinallyExample;

(**
* Will write the string 'Text' to the file 'FileName'
* There are several procedures/functions I use in this example that you've
* never seen before. Don't panic! Click on the triangle beside 'Files' in the
* functions list and you'll see them all
*)
function WriteToFile(Text, FileName: string): Boolean;
var
thePath: string;
theFile: Integer; // When working with files, they are always of the Integer type
begin
// When setting the path, be sure you always end with a '\', otherwise you will get errors
thePath := AppPath + 'Scripts\'; // This will save the file in Simba/Scripts (AppPath = Application Path)

try
theFile := RewriteFile(thePath + FileName, False); // Saves the file to thePath and names it 'FileName'
except // An exception would be thrown most likely if there was an invalid file name
WriteLn('Error opening file!');
finally
WriteLn('Done trying to open file');
end;
// Notice how I assigned the opened or created file to 'theFile', this is so we can use it later in the procedure

if (WriteFileString(theFile, Text)) then
Result := True;

CloseFile(theFile); // Remember to ALWAYS close the file when you're finished! If you don't it can cause memory leaks and your script will run very slowly
end;

begin
ClearDebug;
if (WriteToFile('Test!', 'TestFile.txt')) then
WriteLn('Successfully wrote to file!')
else
WriteLn('Error writing to file');
end.


Now that is a lot to take in, but I know you can handle it! Take a look at all the different Simba file handling functions and procedures in the functions list. As you can see there are a lot of different things you can do. Writing to a file can be useful if you want to save progress reports. Maybe your computer crashes or some updates automatically restart the computer while your script is running. Either way, you have your report nicely saved on your computer. :)


If you successfully wrote that script, you debug should look like:

Done trying to open file
Successfully wrote to file!
Successfully executed.Also, navigate to the folder you saved the file to (Simba/Scripts). There should be a nice text file that has "Test!" written in it. :)


If you don't fully understand these statements, don't worry, they're not used often and you can certainly write an awesome Runescape script without them.


Putting it all Together

In this section of the tutorial, you will learn how to make a script using all the different programming statements I've taught you, including having some statements inside other statements (nesting (http://en.wikipedia.org/wiki/Nesting_(computing))). Exciting, no? In this example, I have combined all the different types of statements. Be sure to examine it carefully and make sure you understand everything you are reading. Look back in the tutorial if you need to.

program PuttingItAllTogether;

// To be set by the user of the script
const
TREE_TYPE = 'Willow';
LOGS_TO_CUT = 100;

// Global vars can be 'reset' at any time during your script
var
TotalLogs: Integer;
TreeName: string;
TreeExp, TotalExp: Extended;

// Checks to see if the constants were set properly
function CheckSetup: Boolean;
var
s: string;
logs: Integer;
begin
if (TREE_TYPE = '') then // If the tree type wasn't filled out
begin
WriteLn('Please enter a tree type at the top of the script');
Exit;
end;

s := Lowercase(TREE_TYPE);
if ((s <> 'normal') and (s <> 'oak') and (s <> 'willow')) then // if tree type isn't a valid tree
begin
WriteLn('Please enter a valid tree type at the top of the script');
Exit;
end;

if (LOGS_TO_CUT <= 0) then
begin
WriteLn('Please enter a number of logs to cut at the top of the script');
Exit;
end;

Result := True; // Set to true at the end because if there was an error, it exits and therefore the result is set to false
end;

// Notice the general layout of this function ;)
procedure SetTreeProperties(Tree: string);
begin
case Lowercase(Tree) of
'normal':
begin
TreeName := 'Tree';
TreeExp := 25;
end;

'oak':
begin
TreeName := 'Oak tree';
TreeExp := 37.5;
end;

'willow':
begin
TreeName := 'Willow tree';
TreeExp := 67.5;
end;

else
WriteLn('Invalid tree type in "GetTreeType"');
end;
end;

procedure IncTotalLogs(HowMuch: Integer); // Inc = Increment
begin
IncEx(TotalLogs, HowMuch); // This will increment TotalLogs by HowMuch; if HowMuch = 10, TotalLogs would increase by 10
WriteLn('Increased total logs by -> ' + IntToStr(HowMuch));
WriteLn('Total logs chopped -> ' + IntToStr(TotalLogs));
end;

procedure SetTotalExp;
begin
TotalExp := (TotalLogs * TreeExp); // Multiply the total logs by the tree's exp
WriteLn('Total experience gained -> ' + FloatToStr(TotalExp));
end;

function WriteReportToFile: Boolean;
var
theFile: Integer;
thePath: string;
begin
thePath := AppPath + 'Scripts\Progress.txt';

try
theFile := RewriteFile(thePath, False);
except
WriteLn('Error opening file!');
end;

WriteFileString(theFile, 'Tree: ' + TreeName + #13 + #10); // The '#13 + #10' will skip to the next line in the file, so Exp: won't be written on the same line
WriteFileString(theFile, 'Exp: ' + FloatToStr(TreeExp) + #13 + #10);
WriteFileString(theFile, 'Total Logs: ' + IntToStr(TotalLogs) + #13 + #10);
WriteFileString(theFile, 'Total Exp: ' + FloatToStr(TotalExp) + #13 + #10);

CloseFile(theFile); // Again, don't forget this!
end;

begin
ClearDebug;

if (CheckSetup) then
WriteLn('Script has been setup properly')
else
TerminateScript; // Simply terminates the script when called

SetTreeProperties(TREE_TYPE); // Be sure to call this, otherwise the global vars aren't set

repeat
IncTotalLogs(Random(28)); // Will increase the TotalLogs by a random number from 0-28
SetTotalExp;
until(TotalLogs >= LOGS_TO_CUT); // StrToInt() avoids a type mismatch error

WriteReportToFile;

WriteLn('Finished!');
end.


I know that looks like a lot, and most likely it will be confusing to you, but don't give up. Remember that you have to be patient when learning how to script, you aren't going to understand everything the first time. ;)


If you understand the above script, and managed to experiment successfully, when you hit run, the debug box should get spammed by a bunch of words. When finished, it should look like this:

Finished checking the user's setup
Script has been setup properly
Increased total logs by -> 2
Total logs chopped -> 2
Total experience gained -> 135
Increased total logs by -> 18
Total logs chopped -> 20
Total experience gained -> 1350
Increased total logs by -> 27
Total logs chopped -> 47
Total experience gained -> 3172.5
Increased total logs by -> 5
Total logs chopped -> 52
Total experience gained -> 3510
Increased total logs by -> 23
Total logs chopped -> 75
Total experience gained -> 5062.5
Increased total logs by -> 17
Total logs chopped -> 92
Total experience gained -> 6210
Increased total logs by -> 1
Total logs chopped -> 93
Total experience gained -> 6277.5
Increased total logs by -> 6
Total logs chopped -> 99
Total experience gained -> 6682.5
Increased total logs by -> 13
Total logs chopped -> 112
Total experience gained -> 7560
Finished!
Successfully executed.

Also, you need to check the file that was created from that script. Open Simba/Scripts/Progress.txt and a notepad file should open that looks something like this:


http://i.imgur.com/RnDU09N.png


Congratulations! You now know the basics of programming in Simba. You now have enough knowledge for me to introduce you to what it takes to make a working RuneScape script.



The SRL Include

Remember at the start of the guide when I said you needed to download SRL properly? Well here is why... SRL is comprised of all sorts of functions/procedures available for you to use. Each of them make you scripting life easier. In order to use these handy functions, you have to include and setup SRL in your script. You can do so by setting up you script like this:

program New;
{$i SRL\SRL.simba} // Be sure to add this to ALL your scripts!

begin
SetupSRL; // You also have to call this in your mainloop, otherwise the mouse will move about 1 pixel every 10 seconds :p
end.

At this point you should set that script as your default script. Meaning that every time you open Simba or open a new tab, you will be greeted with a script that already has SRL setup for you. :) Simply to to File > Save as Default.

Now, if you navigate to Simba/Includes/SRL/SRL/, you should see three folders: skill, misc and core. When you include SRL (srl.simba), you are only including the core folder. Any other files you wish you include have to be done separately.

For example, if I was making a script where I needed to cast some spells, I would include the Magic.simba file found in the skills folder because it has many different functions and procedures to help me script for magic. To include that file I'd simply add this at the top of my script:

{$i srl/srl/skill/magic.simba}

The same would be done for any skill file or any file in the misc folder. Don't be afraid to take a look through them, I'm sure you'll find some very handy functions laying around. ;)

Remember the functions list? Well, you'll notice that there is now a little triangle beside the word Includes. Click it, it will show the list of all the functions you have included in your script.

Well there you go, you now know how to use any file in the SRL include. :)



DeclarePlayers & S.M.A.R.T.

The first thing you should know about making script run for RuneScape is about the DeclarePlayers. DeclarePlayers is a procedure that allows you to setup your RuneScape account(s). For example, the username, password, how many logs to cut, how many loads to bank. Obviously those are just a few examples, but the possibilities are endless.

If you've used any scripts at SRL, then you've probably used S.M.A.R.T. (Simba Minimizing Autoing Resource Thing) created by Benland100. This tool allows you to run a script in Simba, and still do whatever you want on your computer. You still can, of course, use a standard internet browser if you wish.

Every DeclarePlayers procedure has to be setup like this, otherwise your script won't work properly. You can, of course add attributes to allow the user to customize each player, but these are the minimum requirements. I also show you how to use S.M.A.R.T., so pay attention!

program DeclarePlayers;
{$DEFINE SMART} // This is how we include SMART; it HAS to be called BEFORE SRL!
{$i srl/srl.simba}

procedure DeclarePlayers;
begin
HowManyPlayers := 1; // This is set to the total amount of players (more on multiplayer later ;)), for now, just keep it set as 1
NumberOfPlayers(HowManyPlayers); // This is a procedure in SRL which sets up player arrays (also, more on that later), this will always be the same
CurrentPlayer := 0; // This is the player to start with; the first player will always be 0 (you'll find out when you learn all about arrays)

Players[0].Name := ''; // Username
Players[0].Pass := ''; // Password
Players[0].Nick := ''; // 3-4 lowercase letters from username; used for random event detection
Players[0].Active := True; // Set to true if you want to use Player 0
Players[0].Pin := ''; // Leave blank if the player doesn't have a bank pin
end;

begin
ClearDebug;
SetupSRL;
DeclarePlayers; // Calls the procedure, you can't forget this!
LoginPlayer; // You want your player to login, right?
end.

I don't expect you to understand everything (like the "Players[0]."), but you should know how to add SMART to your script and how to login your player. You will learn all about Players if you decide to move on to my intermediate and advanced tutorials (just a little glimpse - Players is an array custom type which store all the different player's information. Confused? :p).

Since you now have a DeclarePlayers procedure, lets make our player log in, shall we? Fill out the DeclarePlayers accordingly (with your username/password/nickname), and hit run. Wait a few seconds and you should see the SMART window pop up and the script should execute after you player has been logged in. Your debug box should look something like:

SRL Compiled in 16 msec
SMART Initialized.
Loaded: Server 152, Members: False, Signed: True, Super Detail: False.
Welcome to Runescape.
Username Here
Successfully executed.
Congratulations! You now know all about DeclarePlayers and how to login a player. I bet it wasn't as hard as you thought. :rolleyes:



Failsafes

Failsafes are essential in ALL scripts made for RuneScape. Failsafes are what make the script last for hours without error. They can be made using all the programming statements, but are most commonly conveyed using if statements. Here's a general layout.

if (Condition1) then
Action1 // Recall that there's no semicolon here
else
if (Condition2) then
Action2
else
if (Condition3) then
Action3
else
if (Condition4) then
Action4; // Semicolon because it's the last statement

See how there is always another procedure or "failsafe" to run if the one before it fails? The chances of all four procedures failing isn't very high, hence why some scripts can run for hours - they have awesome failsafes!

Now, before you rush ahead and read the next example, there are a few things I need to explain so you aren't confused. If you looked at it already, you probably asked yourself "MSX1? What's that?". Those are constants in the SRL include that define coordinates on the RuneScape screen. You'll find them to be very helpful while scripting:

MS - Main Screen - The main RuneScape playing screen.
MM - MiniMap - The RuneScape minimap in the top right corner of the RS screen.
MI - Main Inventory - You inventory box on the right of the RS window, below the minimap.
MC - Main Chat - The RS Chat box at the bottom on the RS window.
MB - Main Bank - The RS bank.
DB - Deposit Box - The RS deposit box.

Now, to search in one of these boxes, all you have to do is write the two letters, followed by X1, Y1, X2, Y2. There are also center points for each of these boxes, which would have the two letters followed but one of CX or CY. These constants can be found in Simba/Includes/SRL/SRL/core/Globals.simba. If you don't understand, you will after you read this example (keep in mind I don't use every type of box):

program FailsafesExample;
{.include SRL/SRL.simba}

procedure FailsafeExample;
var
x, y : Integer;
begin
if FindColor(x, y, 2167538, MSX1, MSY1, MSX2, MSY2) then // If the color (2167538) is found, the coordinates of where it was found is stored in the variables (x, y).
MMouse(x, y, 4, 4) // Moves the mouse to x, y; 4, 4 is the randomness on x, y
else

begin
Wait(1000); // Remember 1000ms = 1s
WriteLn('First FindColor failed, trying second...');
if FindColor(x, y, 3652378, MMX1, MMY1, MMX2, MMY2) then
Mouse(x, y, 4, 4, True) // This moves AND left clicks the mouse with randomness 4, 4; 'True' = Left click; 'False' = Right click
else

begin
Wait(1000);
WriteLn('Second FindColor failed, trying third...');
if FindColor(x, y, 4981245, MIX1, MIY1, MIX2, MIY2) then
MMouse(x, y, 4, 4)
else

begin
Wait(1000);
WriteLn('Third FindColor failed, trying forth...');
if FindColor(x, y, 6478356, MCX1, MCY1, MCX2, MCY2) then
Mouse(x, y, 4, 4, True)
else

begin
Wait(1000);
WriteLn('Forth FindColors failed, logging out');
Logout; // This is pretty straight forward, it logs your player out
end;
end;
end;
end;
end; // There are so many 'end's because each begin has to have an end, otherwise you will get an "Identifier expected..." error

begin
ClearDebug;
FailsafeExample;
end.

I made that example to purposely fail, so you would get the idea of how a failsafe works. Do you understand what they do? Do you understand how to move the mouse, how to click the mouse? Do you understand how to specify which box you want to look in? Keep in mind that the box can be any integer values you wish. These constants are just there for your convenience.

If you successfully wrote the above script, when you hit play, the debug box should read:
First FindColor failed, trying second...
Second FindColor failed, trying third...
Third FindColor failed, trying forth...
Forth FindColors failed, logging out
Successfully executed.That is just one example of a failsafe. There are literally 1000s of possibilities, some of which I hope to show you in the more advanced tutorials. You are now finished learning all about failsafes. Now, on to the last part of the tutorial. :)


Antiban and AntiRandoms

Antiban and AntiRandoms are also an essential to ALL RuneScape scripts. The definitions should be pretty straight forward, but I'll explain them anyhow.

Antiban - Procedures/functions that prevent your character from getting banned. Antiban makes your character look more "human-like". Movements like random camera angle motions, random examination of objects/items or random game tab (inventory, quest, music, etc) clicking, etc. Again, there are 100s of possibilites.


AntiRandoms - Procedures/Functions that solve the many RuneScape random events. Don't panic! All the solvable random events are already implimented into SRL. The only thing you have to do is add one line of code. ;)


Antiban

Almost all Antiban procedures are made using a case statement. There are also several antiban procedures already in SRL. All we have to do is put a few of them together, and away we are.


First, I want you to go to your SRL folder and open Antiban.simba (Includes/SRL/SRL/core/Antiban.simba). See how there are several antiban procedures? If you want to know what they do, click the one you want on the functions list, scroll up a bit, and you will see a description of the procedure, and how to use it. Here is an example of a typical antiban procedure (usually common in every script, no matter the author):

(**
* The reason I used Random(60), even though there are only 6 antiban
* procedures is because if you antiban too much, you will look like a bot.
* You want to antiban approx. once every ten times the procedure is called
*)
procedure Antiban;
begin
case Random(60) of // Random(60) generates a random integer from 0 to 59
10: RandomRClick;
20: HoverSkill('Mining', False);
30: PickUpMouse;
40: RandomMovement;
50: BoredHuman;
59: ExamineInv;
end;
end;

Antiban procedures can be as basic or as advanced as you want them. The more advanced, the better, obviously. Everytime the above procedure is called in your script, if the result from Random(60) equals 10, 20, 30, etc., then it will do the corresponding antiban procedure. Neat, huh?



AntiRandoms

Knowing the definition, I'm sure you are thinking it's going to be extremely difficult to implement random event solving in your script. Well, you thought wrong. :p It is actually very, very simple. The first thing you should do is add this little piece of code to your DeclarePlayers procedure:

Players[0].BoxRewards := ['Xp', 'mote', 'ostume', 'oins', 'aphire', 'ssence'];

Any other rewards can easily be added. This line will randomly choose one of the options when a reward box is opened. The 'Xp' option is the option to get a gene lamp.


If you are wondering why there is '' around each option, it is because they are strings, and that's how strings are declared, remember? Also, a positive to having that in your DeclarePlayers procedure is that the user of the script can choose different rewards for different players.


You should also know why there are [] around all the strings. This is because it's a TStringArray (you'll learn more on arrays in the more advanced tutorials).


Now, on to what we need to write as a procedure. Here is an example of a common AntiRandoms procedure and when it may be called:

procedure AntiRandoms;
begin
FindNormalRandoms; // Whenever this is called, the script will check to see if your character is in a random event
LampSkill := 'woodcutting'; // If you set the script to choose an experience lamp from a random event box, it will use the exp on the woddcutting skill

LevelUp; // This is an Antiban procedure, but I find it more useful when called here because AntiRandoms is usually called more often than Antiban
end;

procedure ChopTrees;
begin
// Chopping trees code here
while (IsChopping) do // IsChopping isn't an actual function, it is one I made up for this example, so don't go try using it in one of your scripts ;)
begin
Antiban; // This is an example of when you would call an antiban procedure
AntiRandoms; // Call AntiRandoms while your character is chopping down a tree
end;
end;

See? I bet that's much easier than you expected. So basically, while your character is hacking away at a tree, the script will continually search for random events, so if you happen to end up in one, the script can solve it without problems. I highly recommend you put FindNormalRandoms in almost all of your procedures so that no matter where you get sucked into a random event, your script can still attempt to solve it.

Well, that's it for Antiban and AntiRandoms. Every script you write for RuneScape should include both of these. These significantly decrease your changes at a ban (not that the chances are very high to begin with). Also, don't be afraid to use your imagination and create your own Antiban procedures. Remember, not EVERYTHING is in SRL. ;)



Conclusion

Well there you have it! My beginner's tutorial. To be quite honest, you probably won't be able to make a RuneScape script with what you've learned so far. But don't worry! You've learned what it takes to make a working script. You know the basics, and everything from here on in is just learning the different Simba commands and how to use them (with a few new programming concepts here and there).

Remember to always ask questions if you're unsure about something. I have no problem giving a more detailed explanation on something if you need it. Don't be afraid to post your questions and either I or someone else from the community will replay as soon as possible.

I would also like to encourage you to post any scripts you write that started with this tutorial. It's always nice to see how this has helped people. Also, if you just want me to take a look over your script and give you detailed feedback/suggestions, feel free to post it here. :)

In the meantime, see if you can tackle my Intermediate Tutorial (not actually finished yet) in the intermediate scripting tutorials section. Until that is finished, you can continue with the intermediate/advanced sections in my AIO SCAR Scripting Tutorial (http://villavu.com/forum/showthread.php?t=49089). I hope this helped you learn the basics of programming. :)

Cheers,
Coh3n

Coh3n
09-13-2010, 04:09 AM
This took me a few months to rewrite, so I wouldn't expect the intermediate guide to be finished anytime soon, since I now have even less time with school and hockey. Nevertheless, enjoy!

Coh3n

TomTuff
09-13-2010, 04:35 AM
you and your tuts coh3n... excellent job, i'll have a better look-see over it later =)

Craig`
09-13-2010, 06:19 AM
nice job, bro.

just power skimmed and it's noice :), perhaps:


The begin..end. is called your Main Loop. SCAR will read the code in your main loop as your script and run is as you please. If you would like SCAR to run a function or procedure, you have to include them in your main loop. More on script structure later.

SCAR should be Simba? (although the explanation works for SCAR as well, it's a Simba tutorial :))

Wizzup?
09-13-2010, 07:11 AM
Terrific job. Too bad I can't give you a second Tutorial writers cup. :)

Zyt3x
09-13-2010, 07:15 AM
OMF... Wow.. Great job as always! Rep++ :)

HyperSecret
09-13-2010, 10:11 AM
Very nice Cohen!

Coh3n
09-13-2010, 05:21 PM
nice job, bro.

just power skimmed and it's noice :), perhaps:



SCAR should be Simba? (although the explanation works for SCAR as well, it's a Simba tutorial :))
Nice find. :) Fixed.


Terrific job. Too bad I can't give you a second Tutorial writers cup. :)
Ha, well someone's gotta start some Simba tutorials, I figured it'd be me. :p

To the rest of you, thanks. :)

Naum
09-13-2010, 05:33 PM
Very nice, very nice indeed

DeSnob
09-14-2010, 01:57 AM
Wtfhax. I wish this was around when I began to learn how to script. (I remember when I finally learned how to use MMouse lol)

Coh3n
09-14-2010, 02:05 AM
Wtfhax. I wish this was around when I began to learn how to script. (I remember when I finally learned how to use MMouse lol)
My AIO guide was probably around, but I'm assuming you mean for Simba.

Overtime
09-15-2010, 07:01 AM
Found an error on the top part or "Part 1" as i should say you have


Writeln('We are chopping ' + TreeToCut + ' trees!');


as you should have

Writeln('We are chopping ' + Tree_To_Cut + 'trees!');


Because your Const is TREE_TO_CUT, i kept getting a error when i entered the first time, and then i remeberd you have to claim it the exact same way or it will give an error

Thanks learned from part one and will more on to part 2 "standards" later

My brain hurts xD lol

Coh3n
09-15-2010, 05:34 PM
Found an error on the top part or "Part 1" as i should say you have


Writeln('We are chopping ' + TreeToCut + ' trees!');


as you should have

Writeln('We are chopping ' + Tree_To_Cut + 'trees!');


Because your Const is TREE_TO_CUT, i kept getting a error when i entered the first time, and then i remeberd you have to claim it the exact same way or it will give an error

Thanks learned from part one and will more on to part 2 "standards" later

My brain hurts xD lol
Nice find, thanks. I thought I actually ran all the example I made, but apparently I missed one. :p

Thanks, and good luck with the rest of the guide. ;)

dhandley12
09-26-2010, 02:37 AM
Thank you for spending so much time to write this tut. I'm a newbie when it comes to scripting so I was having trouble just using scripts and this guide has really helped me out. :)

Coh3n
09-26-2010, 06:07 AM
Thank you for spending so much time to write this tut. I'm a newbie when it comes to scripting so I was having trouble just using scripts and this guide has really helped me out. :)
I'm glad it helped you out. :)

Dgby714
09-26-2010, 06:41 AM
Very nice guide =)


Small Note: I personally like too keep things like "string, integer, boolean" (Built-in types) all lowercase.
Then Types added like "Players, TStringArray, TItem" in its original camel caps

Coh3n
09-28-2010, 02:23 PM
Very nice guide =)


Small Note: I personally like too keep things like "string, integer, boolean" (Built-in types) all lowercase.
Then Types added like "Players, TStringArray, TItem" in its original camel caps
Did I say they should be capitalized? String should be lowercase because it's bold, but for the others, I think it's up to the scripter.

BraK
09-28-2010, 03:17 PM
Wanted to point out this bit to you.

// Using a function
function WeAreBored: string;
var // Declareing variables locally
s: String;
begin
Result := 'What are we going to do now?'; // Notice that "Result" is a string because the function returns a string
s := 'We are very bored chopping all these logs!';
Wait(500);
Writeln(s); // Notice no "IntToStr" because the variable "s" is already a string
Wait(500);
Writeln(Result);
Wait(500);
end;

begin // Don't forget to put your procedures/functions in the main loop!
ClearDebug; // This procedure just clears the debug box when you click run
HowManyLogs;
WeAreBored;
end. //Notice the '.', signalling the end of the script

Your not actually using the function as a function in this instance. WeAreBored is not outputing anything. it's just doing the writeln's inside the routine. Nice Tut though. Still reading I post anymore that I see.

Coh3n
09-28-2010, 05:58 PM
Wanted to point out this bit to you.

Your not actually using the function as a function in this instance. WeAreBored is not outputing anything. it's just doing the writeln's inside the routine. Nice Tut though. Still reading I post anymore that I see.
Thanks BraK. Fixed now. :)

BraK
09-28-2010, 07:11 PM
Your Tutorial is really good. I learned a bit from the try except finally part. Then had a good long look at my Tut and had a realization. I need to work on my writing skills more. My tut looks like crap compared to yours.

Coh3n
09-28-2010, 07:15 PM
Your Tutorial is really good. I learned a bit from the try except finally part. Then had a good long look at my Tut and had a realization. I need to work on my writing skills more. My tut looks like crap compared to yours.
Haha, I'm pretty anal about organization and stuff like that. :p

anonymity
09-28-2010, 07:25 PM
Beautifully done Coh3n! It is nice, clean, intuitive. You and your tuts.. Well done good sir, well done.

Coh3n
10-27-2010, 06:04 AM
Beautifully done Coh3n! It is nice, clean, intuitive. You and your tuts.. Well done good sir, well done.
Thanks anonymity. :)

Red Fuel Tank
10-30-2010, 04:06 PM
Nice tutorial Coh3n.

Any chance you could make a worksheet or quiz-sheet to exercise what is learned from the tutorial?
(i.e. - "Make a script that..." or "What does ______ do?")

I hope I don't sound silly asking this.

Troll
10-30-2010, 05:03 PM
Great this has helped me loads, thanks.

Hello, and welcome to the first of three of my all-in-one scripting tutorials.
Just one question how can you have three all in ones? Won't it be All in Three? :p

Anyway thanks for this

Coh3n
10-30-2010, 09:36 PM
Nice tutorial Coh3n.

Any chance you could make a worksheet or quiz-sheet to exercise what is learned from the tutorial?
(i.e. - "Make a script that..." or "What does ______ do?")

I hope I don't sound silly asking this.
You don't sound silly. :p I like the idea and would do it if I had the time. However, I barely have any time nowadays. :(


Great this has helped me loads, thanks.

Just one question how can you have three all in ones? Won't it be All in Three? :p

Anyway thanks for this
Lol. :p

All-in-one Beginner, All-in-one Intermediate and All-in-one Advanced. That's the plan anyway, but I don't think I'll have time to write those for a while.

Kaladin
11-06-2010, 11:34 PM
Great intro to programming, covered alot of basics as well as the specific RS ones.

Thanks alot :)

the smith400
11-11-2010, 01:24 AM
Now.. this is abit stupd but i'm just doing this for fun to learn.

program FindStart;

const
NUMBER_PREF = 67;
LOWEST_NUM = 0;
HIGHEST_NUM = 1000;
procedure FindCalc;
begin
Writeln('Prepare for the answer...')
Wait(700)
Writeln('Anytime now!')
Wait(1700 + Random(420))
Writeln('The random number generated between ' + IntToStr(LOWEST_NUM) + ' and ' + IntToStr(HIGHEST_NUM) + ' is!')
Wait(3500 + Random(540))
if (Random(HIGHEST_NUM) < (NUMBER_PREF)) then
Writeln('Less Than ' + IntToStr(NUMBER_PREF) + '!')
else
Writeln('Greater Than ' + IntToStr(NUMBER_PREF) + '!');
end;

begin;
ClearDebug;
FindCalc;
end.

There is one part which I'm not sure what to do..

if (Random(HIGHEST_NUM) < (NUMBER_PREF)) then

How can i generate Random Number between, HIGHEST_NUM and LOWEST_NUM ?

Edit: Oh, and what should I do to generate the random number the script has created?

So I could say that the number is not (NUMBER_PREF) but instead the random number given?


I might be on the right track with one of the problems but I may have approached it in the wrong way.
if (RandomRange(StrToInt(HIGHEST_NUM),StrToInt(LOWEST _NUM) < (NUMBER_PREF))

or

if (RandomRange(HIGHEST_NUM;LOWEST_NUM) < (NUMBER_PREF)) then

traveler
11-11-2010, 01:29 AM
the smith400, you would do something like this


if (RandomRange(LOWEST_NUM,HIGHEST_NUM) < (NUMBER_PREF)) then

Runescape Pro
11-11-2010, 01:40 AM
Wouldn't this also work(?):


if ((Random(HIGHEST_NUM) - LOWEST_NUM) < (NUMBER_PREF)) then

the smith400
11-11-2010, 01:48 AM
Wouldn't this also work(?):


if ((Random(HIGHEST_NUM) - LOWEST_NUM) < (NUMBER_PREF)) then

Not really.
I understand how you would think that. If you subtract the lowest by the highest you'll have that many posible solutions. Example, 1000-100 will equal 900. But if you want 950 to be your preferred number, then it will be outside the difference range of 0 to 900.

I'm looking for the number between 100 and 1000 and not the number between the difference of 100 and 1000.


One more thing, how can I post in the debug box the random number that was generated?

Runescape Pro
11-11-2010, 01:56 AM
Oooooh. I got it.

Umm.. I would set the generated number as a variable. Like "RanNumGen: Integer;"

The you can print that by "Writeln(IntToStr(RanNumGen));"

To get the number in the variable would be: "RanNumGen:=RandomRange(LOWEST_NUM,HIGHEST_NUM);"

I believe that's how it's done.

In the order:
1: Set the variable name/type.
2: Generate the random number.
3: Use writeln to get it into the debug box.

Note: hope this helps. I wrote it as easy to understand as I could.

traveler
11-11-2010, 01:58 AM
to post the number to the debug box, do something like this


writeln(IntToStr(NUMBER_PREF));


E: didnt see runescape pro's post. And his way would be better, to have the random number set to a variable then Writeln() the variable.

the smith400
11-11-2010, 02:24 AM
Oooooh. I got it.

Umm.. I would set the generated number as a variable. Like "RanNumGen: Integer;"

The you can print that by "Writeln(IntToStr(RanNumGen));"

To get the number in the variable would be: "RanNumGen:=RandomRange(LOWEST_NUM,HIGHEST_NUM);"

I believe that's how it's done.

In the order:
1: Set the variable name/type.
2: Generate the random number.
3: Use writeln to get it into the debug box.

Note: hope this helps. I wrote it as easy to understand as I could.

Worked like charm!
Thank you!

otavioafm
11-29-2010, 09:45 PM
iTS VERRY HARD!!!!

WT-Fakawi
11-30-2010, 08:19 PM
iTS VERRY HARD!!!!Yes it is. But you will get there, and once you do, there is nothing going to stop you!

tofurocks
02-15-2011, 12:35 AM
Great tutorial, thanks.
Very to the point :)

Santa
03-20-2011, 06:33 PM
Dude this has so much information! Great guide.. thanks sooo much :)

Baked0420
03-21-2011, 08:56 PM
Pretty nice guide, I actually learned something. I never knew exactly how try except finally worked, but that's because I never felt the need to use it.

One thing though, you say Random(60) generates a random number 0-60. It actually generates 60 random numbers, 0-59, so ExamineInv would never get called since you have it as 60 in the case. Just letting you know so you can fix it in the tut.

Yago
03-21-2011, 10:01 PM
Wow gotta change my script ...

Coh3n
03-21-2011, 10:40 PM
Pretty nice guide, I actually learned something. I never knew exactly how try except finally worked, but that's because I never felt the need to use it.

One thing though, you say Random(60) generates a random number 0-60. It actually generates 60 random numbers, 0-59, so ExamineInv would never get called since you have it as 60 in the case. Just letting you know so you can fix it in the tut.
Hm, I'm sure I would have tested that. Oh well, thanks for pointing it out. I'll fix it now. :)

Derot
04-11-2011, 08:16 PM
Thank you so much for this guide. I lost my account my old account that used to be just a junior member and I never really took the time to learn scipriting. But I now have the motivation to do so thanks for this guide.

I am new
05-27-2011, 10:48 PM
Guide seems nice and everything seems explained very well for a beginner. But for some iffy reason I am unable to compile any scripts, everytime I try to compile it debugger gives this error on function Writeln:
[Error] (9:20): Invalid number of parameters at line 8
Compiling failed.

this one was given when I tried to compile your second example "puttingthebasicstogether". Any ideas what could be wrong? I have installed Simba exactly like told in guide you linked in the beginning of your tutorial. I am willing to learn but this started pretty badly! Hopefully I get some answers :P!
This is my code which I simply copied to simba (Didn't c&p):

program Laitetaan_kamat_kasaan;

var
Logs: Integer;
Exp: Extended;

const
NUMBER_OF_LOGS = 500;
TREE_TO_CUT = 'Magic';

procedure HowManyLogs;
begin
Logs:= 250;
Exp:= 195.5;

Writeln***40;'We have chopped' + IntToStr***40;Logs***41; + 'logs this session!'***41;;
Wait***40;500***41;;
Writeln***40;'We Want to chop' + IntToStr***40;NUMBER_OF_LOGS***41; + 'logs.'***41;;
Wait***40;500***41;;
Writeln***40;'We are chopping' + TREE_TO_CUT + 'trees!'***41;;
Wait***40;500***41;;
Writeln***40;'We have gained' + FloatToStr***40;Logs * Exp***41; + 'xp this session!'***41;;
end;

function WeAreBored: string;
var
s:String;
begin
Result:= 'What are we going to do now';
s:= 'we are very bored chopping all these logs!'
Wait***40;500***41;;
Writeln***40;s***41;;
end;
begin
ClearDebug;
HowManyLogs;
Writeln***40;WeAreBored***41;;
end.

Home
05-27-2011, 11:02 PM
Guide seems nice and everything seems explained very well for a beginner. But for some iffy reason I am unable to compile any scripts, everytime I try to compile it debugger gives this error on function Writeln:
[Error] (9:20): Invalid number of parameters at line 8
Compiling failed.

this one was given when I tried to compile your second example "puttingthebasicstogether". Any ideas what could be wrong? I have installed Simba exactly like told in guide you linked in the beginning of your tutorial. I am willing to learn but this started pretty badly! Hopefully I get some answers :P!
This is my code which I simply copied to simba (Didn't c&p):

program Laitetaan_kamat_kasaan;

var
Logs: Integer;
Exp: Extended;

const
NUMBER_OF_LOGS = 500;
TREE_TO_CUT = 'Magic';

procedure HowManyLogs;
begin
Logs:= 250;
Exp:= 195.5;

Writeln***40;'We have chopped' + IntToStr***40;Logs***41; + 'logs this session!'***41;;
Wait***40;500***41;;
Writeln***40;'We Want to chop' + IntToStr***40;NUMBER_OF_LOGS***41; + 'logs.'***41;;
Wait***40;500***41;;
Writeln***40;'We are chopping' + TREE_TO_CUT + 'trees!'***41;;
Wait***40;500***41;;
Writeln***40;'We have gained' + FloatToStr***40;Logs * Exp***41; + 'xp this session!'***41;;
end;

function WeAreBored: string;
var
s:String;
begin
Result:= 'What are we going to do now';
s:= 'we are very bored chopping all these logs!'
Wait***40;500***41;;
Writeln***40;s***41;;
end;
begin
ClearDebug;
HowManyLogs;
Writeln***40;WeAreBored***41;;
end.

Please upload it to attachment :)

~Home

I am new
05-27-2011, 11:41 PM
There You go

masterBB
05-28-2011, 01:38 PM
There You go

There is currently a bug within these forums. They display code wrong: replace ***40; with ( and ***41; with )

edit: included fixed file.

I am new
05-28-2011, 02:17 PM
Thank you very much :D

Coh3n
05-28-2011, 06:37 PM
Yeah sorry about that. Running this (or what Home posted) will work. Hopefully the foum bug is fixed soon.

program Laitetaan_kamat_kasaan;

var
Logs: Integer;
Exp: Extended;

const
NUMBER_OF_LOGS = 500;
TREE_TO_CUT = 'Magic';

procedure HowManyLogs;
begin
Logs:= 250;
Exp:= 195.5;

Writeln('We have chopped ' + IntToStr(Logs) + 'logs this session!');
Wait(500);
Writeln('We Want to chop ' + IntToStr(NUMBER_OF_LOGS) + 'logs.');
Wait(500);
Writeln('We are chopping ' + TREE_TO_CUT + 'trees!');
Wait(500);
Writeln('We have gained ' + FloatToStr(Logs * Exp) + 'xp this session!');
end;

function WeAreBored: string;
var
s:String;
begin
Result:= 'What are we going to do now';
s:= 'we are very bored chopping all these logs!'
Wait(500);
Writeln(s);
end;

begin
ClearDebug;
HowManyLogs;
Writeln(WeAreBored);
end.

I am new
05-28-2011, 07:58 PM
Okay I have now read entire tutorial and all I can say is damn nice job! It was easy to understand and your guidance was easy to follow!

Here comes few questions:

I am not interested in current version of rs but I'd like to make few scripts to one private server which is running on 317 cache.

How should i make simba run the script on the servers client?
Could I anyhow load server's client with S.M.A.R.T or is it designed just for RuneScape? If it's like that my only opinion is select the client with simba's client selection tool and I can't run it hidden, right?

Coh3n
05-28-2011, 09:23 PM
How should i make simba run the script on the servers client?
Could I anyhow load server's client with S.M.A.R.T or is it designed just for RuneScape? If it's like that my only opinion is select the client with simba's client selection tool and I can't run it hidden, right?Unless you know Java well enough to modify the SMART source to load from the private server then yes, using the web client is your only option (i.e. it will take control of your mouse).

I'm glad you liked the guide. :)

I am new
05-28-2011, 09:36 PM
Okay thanks for the clearance :P! Will take a look in few other beginners tutorials and try to make few simple scripts by myself and move to your intermediate guide!

Coh3n
05-28-2011, 09:41 PM
Okay thanks for the clearance :P! Will take a look in few other beginners tutorials and try to make few simple scripts by myself and move to your intermediate guide!I haven't actually written the intermediate tutorial for Simba (not sure if I'll ever get around to it), but the one on SCAR is basically the same thing. There's just some things that may not work. If that's the case, just ask. :)

blother
07-03-2011, 03:14 PM
Well, i think this might be my second or third time through this tutorial, but i am finally starting to understand everything (i've looked at it on and off). Not that it is bad because it is a really good tutorial, but i could never get my head wrapped around the concepts. Plus i didn't have the time before to focus on learning it all.

All in all, thanks for the tut and i guess i can start learning how a real runescape script works and making my own.

Coh3n
07-04-2011, 10:50 AM
Well, i think this might be my second or third time through this tutorial, but i am finally starting to understand everything (i've looked at it on and off). Not that it is bad because it is a really good tutorial, but i could never get my head wrapped around the concepts. Plus i didn't have the time before to focus on learning it all.

All in all, thanks for the tut and i guess i can start learning how a real runescape script works and making my own.No problem. Don't be afraid to ask if you're confused about something. :)

catbat78
07-14-2011, 03:06 AM
Thanks for the 5/5 tutorial on pascal code it really helped me understand rookie scripting. :)

I know you said no grammar correction but in the standards section it confused me allot when you spelled "indent" as "intent." That's all, I hope I didn't piss you off. :D

Coh3n
07-15-2011, 12:25 PM
Thanks for the 5/5 tutorial on pascal code it really helped me understand rookie scripting. :)

I know you said no grammar correction but in the standards section it confused me allot when you spelled "indent" as "intent." That's all, I hope I didn't piss you off. :DGlad you liked it, and I encourage grammar correction, not discourage it. ;) Did I make that mistake in the thread also? Fixes to "indenting" by the way. :)

Also, I merged your posts, try not to double post, just edit your original post instead.

BraK
07-15-2011, 12:32 PM
Dang I forgot I could do that stuff here. XD I saw his double post yesterday. I probably could have fixed it too. :( I'll try to keep that in mind in the future. It's not something I do very often.

~BraK

catbat78
07-15-2011, 09:05 PM
Glad you liked it, and I encourage grammar correction, not discourage it. ;) Did I make that mistake in the thread also? Fixes to "indenting" by the way. :)

Also, I merged your posts, try not to double post, just edit your original post instead.
I might of read your intro wrong. Sorry if I did.
PS: Can you PM me and give me a better description of "Condition" in the statements, I'm a bit confused by it. Sorry for asking all these questions, I am quite new to the pascal code. :duh:

Coh3n
07-15-2011, 09:57 PM
I might of read your intro wrong. Sorry if I did.
PS: Can you PM me and give me a better description of "Condition" in the statements, I'm a bit confused by it. Sorry for asking all these questions, I am quite new to the pascal code. :duh:Don't be sorry. :)

Condition refers to a boolean (true or false) statement. Maybe this will help:

function test: boolean;
begin
result := true;
end;

var
i: integer;
begin
if (test) then
writeln('yay');

i := 5;
if (i = 5) then
writeln('yay');
end.

bevardis
08-10-2011, 05:06 PM
It's nice and currently up to date. Thank you.

Jupiter
08-15-2011, 08:55 PM
This is extremely helpful. Thank you so much :)

sf411
09-14-2011, 10:40 PM
Well I have just finished the reading up until the loops part, since my time is running out for today.

I was wondering if you could give me an example of when the repeat..until is better than while..do? Also what would be the benefit of the repeat...until running a command at least once?

Coh3n
09-14-2011, 11:38 PM
Well I have just finished the reading up until the loops part, since my time is running out for today.

I was wondering if you could give me an example of when the repeat..until is better than while..do? Also what would be the benefit of the repeat...until running a command at least once?There's really no circumstance that I can think of where one would be better than the other since they both accomplish the same thing. This is kind of a lame example, but you'll get the idea.

// "Looking for bank screen" will be printed no matter what
repeat
writeln('Looking for bank screen');
wait(randomRange(300, 500));
until(bankScreen());

// "Looking for bank screen" won't be printed if the screen is already open when this loop is called
while (not bankScreen) do
begin
writeln('Looking for bank screen');
wait(randomRange(300, 500));
end;

sf411
09-15-2011, 01:06 AM
Personally, the do while loop is easier for me to understand since I do programming in C++ and the like...but I like the look of repeat until in your example. Since it really all just is a personal preference Ill just flip-flop between the two depending on the kind of function its in.

Thanks for the example, Coh3n!

beleeive
11-09-2011, 07:48 PM
I really hope this doesn't come out the wrong way, but i've been using computers all my life, never programming but i'm not at all technologically impaired

and this is so overwhelming that i'd been planning to begin scripting today and i may have just changed my mind after reading some of this guide. :(

Coh3n
11-09-2011, 08:22 PM
Lol, well, what did you expect? You can't teach someone the basics of programming in a short tutorial. It's the same with any type of class you take in school. You don't take the class for 2 hours and you magically know everything. It takes time.

beleeive
11-09-2011, 08:37 PM
Idk, how'd you originally learn pascal? I wonder if there are some video guides somewhere.

again, i hoped that wouldn't come out the wrong way, I just didn't expect to be so overwhelmed from the start.

Coh3n
11-09-2011, 08:39 PM
Idk, how'd you originally learn pascal? I wonder if there are some video guides somewhere.

again, i hoped that wouldn't come out the wrong way, I just didn't expect to be so overwhelmed from the start.I didn't take it the wrong way. I expect people to be overwhelmed. It's not easy when you first start.

I basically taught myself with help from people here and the odd tutorial. I wrote this one to hopefully make it easier for people like you. I think if you just slowly go through the guide you'll find it to be easier than you think. Just don't try to do too much at once. ;)

Kyle Undefined
11-09-2011, 08:40 PM
Also, if you ever have any questions, you can either ping me on IRC or shoot me a PM :)

beleeive
11-09-2011, 09:09 PM
I didn't take it the wrong way. I expect people to be overwhelmed. It's not easy when you first start.

I basically taught myself with help from people here and the odd tutorial. I wrote this one to hopefully make it easier for people like you. I think if you just slowly go through the guide you'll find it to be easier than you think. Just don't try to do too much at once. ;)

I myself am a hands-on learner, as i repeatedly read through it, i pick up bits and pieces, but i'm tempted to just try teaching myself by opening simba and runescape and just using trial-and-error.

edit; @camo, i appreciate it, i'm sure i'll take you up on that sometime

Coh3n
11-10-2011, 06:53 AM
I myself am a hands-on learner, as i repeatedly read through it, i pick up bits and pieces, but i'm tempted to just try teaching myself by opening simba and runescape and just using trial-and-error.

edit; @camo, i appreciate it, i'm sure i'll take you up on that sometimeWell it's going to take ages if you simply read the guide. You need to actually write out and experiment with the examples I provide.

heronimus
11-20-2011, 06:32 AM
thank you so much for this guide, it really helped me alot in learning pascal.
I do have c++ and java expierience but that begin and end; thing is so weird:duh:
expect my first script soon:spot:

Main
11-22-2011, 10:25 PM
Shouldn't this be stickied as well?

Coh3n
11-22-2011, 10:53 PM
It should have always been stickied.

NexPB
12-04-2011, 04:40 PM
great guide, learned alot from it. Hoping to write some great script in the future.

Tempt
12-06-2011, 10:59 AM
Thank you. I just wanted to let you know that your guide has helped another person start scripting :) What do you recommend as the best way to ease into scripting is? Reading other peoples scripts and trying to understand them?

Coh3n
12-06-2011, 08:35 PM
Thank you. I just wanted to let you know that your guide has helped another person start scripting :) What do you recommend as the best way to ease into scripting is? Reading other peoples scripts and trying to understand them?Yeah, reading other people's code can be very helpful at times, but it can also be very confusing if you run into something you don't understand or if the code you're reading isn't properly documented.

I think the best way is to write your own code and using guides/other scripts as references. That way you can get a feel of what works and what doesn't.

oudshoorn
12-09-2011, 08:06 PM
@Coh3n

I typed some If..then...else statements but they didn't worked so i copy and pasted your line of code and it still says something about wrong amount of parameters at a certain line and gives me an error that looks like this (ERROR: [23:7]) or something
can you help me out here???

Coh3n
12-09-2011, 08:25 PM
@Coh3n

I typed some If..then...else statements but they didn't worked so i copy and pasted your line of code and it still says something about wrong amount of parameters at a certain line and gives me an error that looks like this (ERROR: [23:7]) or something
can you help me out here???
Can you post the code you're trying to run? All my examples should work, so you may have just copied it wrong.

H_N
12-10-2011, 12:44 PM
Thanks for the guide, explained really well :)

minnie
12-11-2011, 01:12 AM
This really helped me out,thank you!

c00ty
12-11-2011, 03:31 AM
Thank man, this tutorial is perfect. It helped me out so much. I am going to move onto intermediate soon.

Rambot
12-11-2011, 10:12 AM
"When you intent, it will be two spaces. You can do this by hitting the "Tab" button on your keyboard, or simply hitting the space bar twice."

Should be indent.

Thank you so much for putting this together! First time working with pascal, so I'll need all the info I can get =].

t0b1as
12-11-2011, 06:21 PM
Thanks for the guide! Going to read all trough it in the next few days ^^

Coh3n
12-11-2011, 06:26 PM
"When you intent, it will be two spaces. You can do this by hitting the "Tab" button on your keyboard, or simply hitting the space bar twice."

Should be indent.

Thank you so much for putting this together! First time working with pascal, so I'll need all the info I can get =].Glad you like it, and fixed the spelling error. :)

DemiseScythe
12-14-2011, 03:41 AM
Nice tutorial, I learn most of what I need to begin scripting, the rest is just practice and experimenting, just one quick question.

{$DEFINE SMART}

I found that part at the top of a public script right under program name but above the srl.scar include. I wonder what it does, I tried searching this site and it did not turn back any relevant results since almost every post on this section has the words define and smart in them.

Is that line the same as {$i srl/srl/misc/smart.scar} ?

Just a quick question, that is all, read many tutorials on here and get most of them, currently reading your intermediate tutorial.

While I am at it, any other include goes in between
{$i srl/srl/misc/smart.scar}
and
{$i srl/srl.scar}
like those are absolute first and last?

kyocera
12-14-2011, 01:09 PM
Thanks I did the whole guide took a few days, I can't even imagine how long it took to write.

eXoTiK
12-14-2011, 09:02 PM
Last updated on my birthday, lolol win.

rswiz
12-18-2011, 12:04 PM
lol, too complex for me... looks like i won't be a member on here for a while =/

lilcmp1
12-20-2011, 04:16 PM
One guide read but it looks like I'll have to reread this a few times. Quite overwhelming

You've done a great job of making it readable to a beginner. Just need to get comfortable and familiar with things :S

Gaston7eze
12-21-2011, 05:07 PM
Got this error:
[Error] (6:1): Unknown identifier 'WriteIn' at line 5
Compiling failed.

Script at the first.
program new;
Procedure WriteinDebugBox;

begin
WriteIn('Hello guys');
end.

RISK
12-21-2011, 05:08 PM
"WriteLn". Not "WriteIn".

Gaston7eze
12-21-2011, 05:13 PM
"WriteLn". Not "WriteIn".

Ohh,mLOL,Thanks bro!

Gaston7eze
12-21-2011, 05:17 PM
program new;
Procedure WritelnDebugBox;
Writeln('Hello')
begin
end.

[Error] (4:1): 'BEGIN' expected at line 3
Compiling failed.

RISK
12-21-2011, 05:19 PM
Procedure WritelnDebugBox;
begin
Writeln('Hello');
end.

Gaston7eze
12-21-2011, 05:47 PM
Also, i have one more question,Whats "Integer"?Thanks, and sorry for my little knowdlage about this.

RISK
12-21-2011, 05:48 PM
It's a variable that holds a number.


Also, i have one more question,Whats "Integer"?Thanks, and sorry for my little knowdlage about this.

Gaston7eze
12-21-2011, 05:56 PM
It's a variable that holds a number.

Thanks,and MY FINAL QUESTION.Do you know any place where can i do exercices to practice?
Thanks!

TheJokester117
12-21-2011, 06:11 PM
Thanks,and MY FINAL QUESTION.Do you know any place where can i do exercices to practice?
Thanks!

What I have been doing is going into the first script sections and finding open source scripts. Then, I've been reading the code and saying what each procedure does, what the variables are, and basically just analyzing the code trying to see what I can actually get out of it.

Besides that, just look at the other tutorials and follow along with them.

Gaston7eze
12-21-2011, 06:32 PM
What I have been doing is going into the first script sections and finding open source scripts. Then, I've been reading the code and saying what each procedure does, what the variables are, and basically just analyzing the code trying to see what I can actually get out of it.

Besides that, just look at the other tutorials and follow along with them.

I will try out what you are saying,thanks man!

CreaShun
12-27-2011, 12:43 AM
I think this is a typo you may want to fix, Step 12 on standards:
// Bad
var
Logs: Integer;
Ores: Integer;
Fish: Integer;

function WalkToBank(i: Integer; j: Integer; l: string; k: string): Boolean;
// Good
var
Logs, Ores, Fish: Integer;
function WalkToBank(i, j: Integer; l, s: String): Boolean;

That should be a "k"

Sorry for being picky, Amazing guide, This is going to be my first step into proggraming. Learning so much right now xD

Typo 2: Again sorry for being anal, but that must mean i'm good at spotting mistakes, that should come in handy while writting scripts. (Step 13 in standards)

// Bad
var
b: Boolean;
// Good
var
DoesBank: Boolean <----- Missing ";"

sahibjs
12-30-2011, 06:02 PM
thanks Coh3n!

Amazing guide, though it took a while to read :P

Everything makes a lot more sense now.

Coh3n
12-31-2011, 02:46 AM
I think this is a typo you may want to fix, Step 12 on standards:
// Bad
var
Logs: Integer;
Ores: Integer;
Fish: Integer;

function WalkToBank(i: Integer; j: Integer; l: string; k: string): Boolean;
// Good
var
Logs, Ores, Fish: Integer;
function WalkToBank(i, j: Integer; l, s: String): Boolean;

That should be a "k"

Sorry for being picky, Amazing guide, This is going to be my first step into proggraming. Learning so much right now xD

Typo 2: Again sorry for being anal, but that must mean i'm good at spotting mistakes, that should come in handy while writting scripts. (Step 13 in standards)

// Bad
var
b: Boolean;
// Good
var
DoesBank: Boolean <----- Missing ";"Why should the 's' be a 'k'? I'll fix the second one, thanks. :)

Yago
12-31-2011, 02:55 AM
Why should the 's' be a 'k'? I'll fix the second one, thanks. :)

The alphabet... i,j,k,l

or the procedure above it

Coh3n
12-31-2011, 02:57 AM
The alphabet... i,j,k,l

or the procedure above itOh, I didn't even realize I did that. I always start integers at i, and strings at s.

Yush Dragon
01-07-2012, 02:07 AM
Coh3n my old friend. Awesome to see that your tutorial is high appreciated by everyone in here. I started to refresh my srl scripting skills again (not that i was good at it before). But thanks to the tutorials you make, it is all possible without any problems ^^. Thank you for spending so much time in this.

Regards,

Yush Dragon

RuNnNy
01-07-2012, 03:48 PM
Thanks Coh3n for the great tutorial, helped me a lot!
Keep up the good work :)

plekter
01-12-2012, 11:29 PM
I am reading up the tutorial as I type this post. I saw that in #11 you explained the different casings weirdly.

Pascal case: GreenButtonType
Camel case: myInt

You explained Pascal case as "... uppercase letter and then camel-capped."
Either that or you just tried to avoid the confusion with overlapping names.

Coh3n
01-13-2012, 12:38 AM
I am reading up the tutorial as I type this post. I saw that in #11 you explained the different casings weirdly.

Pascal case: GreenButtonType
Camel case: myInt

You explained Pascal case as "... uppercase letter and then camel-capped."
Either that or you just tried to avoid the confusion with overlapping names.I explained a Global Variable as "... uppercase letter and then camel-capped." I'm not sure what you think is weird about it?

plekter
01-13-2012, 02:06 AM
I think the term you were looking for was Pascal casing(starts with uppercase and all following words uppercased too). I might be totally mislooking something as the time here is 4 at night and I havent had a coffee yet. :D

Just finished reading the whole tutorial and it was very helpful. I thought that Pascal's syntax will be a lot harder to grasp but it is quite easy, even thought it has some quirks(I have worked too much with C#). Can't wait to get something scripted. :thumbsup:

Now I just got to wrap my tired brain around SRL...

Coh3n
01-13-2012, 02:24 AM
It's not pascal Case because there really is no defined way to case in pascal. You can do it any way you want. You can have whatever standards you want. What I outlined in the first post is just what I recommend and it's clean and easy to read.

Um, maybe I should add a section on using SRL. Or maybe I'll save that for the intermediate tutorial if I ever get around to writing it.

Grognak
01-15-2012, 01:59 AM
Thanks for this! I pushed and read through it all. Pascal is weird to me, but I think I can get used to its quirks.

I have a quick question, why do you use {$i SRL\SRL.scar} instead of {$i SRL\SRL.simba}? As far as I can understand, *.scar doesn't work in the latest version of Simba.

RISK
01-15-2012, 02:00 AM
It's because the guide was not created during SRL5. :)

Grognak
01-15-2012, 02:04 AM
Ah, that makes a great deal of sense. Had to Google a bit for that, haha.

Goon
01-15-2012, 11:28 PM
Thanks for the tut hopefully going to start my first script soon once i learn the basics of simba :)

Foo-Fighter
01-16-2012, 05:57 PM
Thanks for the great guide. Working on actually going through every single part and paying attention instead of just skimming :P. But is has helped a lot!

fearlesskiller
01-18-2012, 09:29 PM
thanks for the guide i hope ill become a good scripter.

momotron
01-19-2012, 12:48 AM
Oh damn. I think i may have found myself a new hobby... and 10 days before an exam as well!!! Great guide :')

begginer
01-20-2012, 10:38 PM
Those taught me some good things

Thanks

C3NTRIX5
01-21-2012, 06:15 AM
Thank you very much Coh3n. This is the beginning of my scripting career!

usb1y
01-23-2012, 05:22 AM
file 'C:\Simba\Includes\SRL/SRL/core/misc/smart.scar' i get this error when running custom scripts i don't think i have any scar files but the simba start scripts run fine just not custom :( please help ill +rep

Coh3n
01-23-2012, 10:28 PM
file 'C:\Simba\Includes\SRL/SRL/core/misc/smart.scar' i get this error when running custom scripts i don't think i have any scar files but the simba start scripts run fine just not custom :( please help ill +repYou have to include it like

program new;
{$DEFINE SMART}
{$i srl/srl.simba}

joehartwig
01-26-2012, 06:35 PM
i am a noob at scripting so much help would be greatly appreciated

Coh3n
01-26-2012, 10:14 PM
The 'end' in a procedure needs to be followed by a ';' not a '.', like you have. Only the mainloop begin..end nest should be followed by a period.

Sassakill
01-29-2012, 07:38 AM
Thanks coh3n!
awesome guide! I think that a lot of people will agree with me on that!

Edit:
Found a typo:


if (Condition) then // Notice the intent after a "begin" statement


Should be:


if (Condition) then // Notice the indent after a "begin" statement

jouri1333
02-01-2012, 10:29 AM
hey coh3n nice guide :D
but where can i find the advanced guide? cuase i cant find it :(

thank you

slakan
02-01-2012, 01:00 PM
Nice guide!

i think im going to read this a couple of times before i start making one my self. There is still alot i dont understand, but i got to translate from english to norwegian at the same time, so things take twice as much time :)

imscaredtolosemymain
02-01-2012, 01:25 PM
OK, is there a working link to the simba wiki, or a list of commands?

I have been having a play pulling others scripts apart and keep finding commands that i cannot get documentation for, for instance

clickmouse2 (note the 2)
getXP

etc.

Now these are in the scripts and working, but are not listed under simba documentation from help tab, nor available from the function list on teh left screen on simba, nor from ctrl+space on blank line.

Where can i get info on all these commands/functions ?

slakan
02-01-2012, 01:31 PM
OK, is there a working link to the simba wiki, or a list of commands?

I have been having a play pulling others scripts apart and keep finding commands that i cannot get documentation for, for instance

clickmouse2 (note the 2)
getXP

etc.

Now these are in the scripts and working, but are not listed under simba documentation from help tab, nor available from the function list on teh left screen on simba, nor from ctrl+space on blank line.

Where can i get info on all these commands/functions ?

the commands are from writes who write there own code :)

they use what they know, and write somthing better :D

imscaredtolosemymain
02-01-2012, 01:41 PM
Slakan,

Do you mean those commands (say getXP) link to some code outside simba? as there is no other occurrence of getXP in the script, defining it as something else, so i have to assume it is a normal simba command? or maybe SMART?

oh and btw, takk for hjelpen! Er du noe i nærheten av Trondheim? Jeg pleide å jobbe der noen ganger

slakan
02-01-2012, 03:19 PM
Haha, nei hedmark :)

men de lager egne functions og procedures som dem setter inn i scripte sitt :)

MSN? face?

slakan_91@hotmail.com add me

imscaredtolosemymain
02-01-2012, 04:02 PM
I knew i would get into trouble posting 'I Norsk'. i can speak any language while connected to google....lol

"but they create their own functions and procedures as those put into the script's"

so for instance, i have seen a 'checkagility' function in a script, which reads the exp of agility; This is like a seperate program/mini script somewhere else, which has a load of lines of code, to do one simple function?

So how are new guys supposed to find out about these? where are they located?

edit: working out the difference between srl and simba - still cannot find good instructions though :(

Coh3n
02-01-2012, 07:17 PM
hey coh3n nice guide :D
but where can i find the advanced guide? cuase i cant find it :(

thank youBecause it hasn't been written. ;) Sorry, I just haven't had the time.


OK, is there a working link to the simba wiki, or a list of commands?

I have been having a play pulling others scripts apart and keep finding commands that i cannot get documentation for, for instance

clickmouse2 (note the 2)
getXP

etc.

Now these are in the scripts and working, but are not listed under simba documentation from help tab, nor available from the function list on teh left screen on simba, nor from ctrl+space on blank line.

Where can i get info on all these commands/functions ?Those functions are in SRL, not Simba. SRL's documentation can be found here (http://docs.villavu.com/srl-5/). Also, you can hold control and click the function in the editor and it will open in another tab (if you wanted to see the source).

imscaredtolosemymain
02-01-2012, 07:59 PM
thanks Coh3n, thats exactly what i was looking for.

Dan the man
02-10-2012, 01:46 PM
Cannot believe i read through that entire beast...

Excellent tutorial mate. Have given me a fair bit of confidence in my scripting journey with SRL. It follows the same principal as all coding languages I am finding (similar to python).

Anyway, THANKSS!!!

crazy5150
02-16-2012, 04:25 AM
I printed your guide at work yesterday before i got off and i already finished. you made it soo simple to understand. plan on reading up the next part in other guide. then reading some simple scripts and decipher them. but yeah ..thnx for spending your time in writing this guide. just wondering if u still planed on revising ur guide like u did for this one??

drfreshtacular
02-17-2012, 02:13 AM
Awesome guide! One thing I did note though. When you mentioned includes ie: {$i srl/srl.simba}, you would occasionally use the file extension .scar instead. I'm new here, but i'm assuming that's what it used to be haha. Just an FYI if you decide to come back and change anything. Thanks!

Coh3n
02-17-2012, 02:55 AM
I printed your guide at work yesterday before i got off and i already finished. you made it soo simple to understand. plan on reading up the next part in other guide. then reading some simple scripts and decipher them. but yeah ..thnx for spending your time in writing this guide. just wondering if u still planed on revising ur guide like u did for this one??I would like to, but don't wait for it. If I do get the time, it won't be for a while, unfortunately.


Awesome guide! One thing I did note though. When you mentioned includes ie: {$i srl/srl.simba}, you would occasionally use the file extension .scar instead. I'm new here, but i'm assuming that's what it used to be haha. Just an FYI if you decide to come back and change anything. Thanks!All switched to .simba, thanks for letting me know. :)

Joe
02-18-2012, 04:55 PM
This helped me a lot! I'll be starting my first script soon.

Rezozo
02-19-2012, 12:12 AM
Same as ^, will start scripting soon. Though I still need to find out what each of the built in SIMBA functions do. Your link to the Simba wiki, and SRL wiki are out and Not Working.

xcenter
02-19-2012, 01:49 PM
Good work, nice guide there.
I hope you make the intermediate guide as soon as possible :)

tutkubakay
02-21-2012, 10:26 PM
thank you i read all

joshj
02-23-2012, 11:17 PM
You said there where some things that won't work in simba from your SCAR tutorial, I was wondering if you could point out a few key things that won't work in simba? It would be greatly appreciated :)

Coh3n
02-24-2012, 06:37 AM
You said there where some things that won't work in simba from your SCAR tutorial, I was wondering if you could point out a few key things that won't work in simba? It would be greatly appreciated :)I don't know exactly what they are. The main differences are that some functions are named differently, and their parameters may differ. The majority are the same, though. I couldn't tell you off the top of my head which ones are different, sorry.

Berwin
03-02-2012, 06:11 AM
I was having some trouble getting MSI setup properly, but I fixed it by deleting Simba off my hard drive and completely reinstalling it. It seems like I've been around for a while, but I haven't used Simba extensively or written any notable scripts. Anyway, thanks for writing the guide, I'm really looking forward to getting started!

osunateosu
03-11-2012, 01:14 AM
Excellent read! After reading this guide and other guides about basic scripting, I feel like I'm ready to move on! One thing I noticed is the SRL wiki page link doesn't seem to work, which isn't that big of a deal. Thanks for the guide, very helpful!

Cheezburgar
03-11-2012, 03:04 AM
Starting to get it xD Thank you so much for doing this!

Coh3n
03-11-2012, 08:27 AM
I don't think the SRL Wiki exists anymore. That may be why the link doesn't work. :p

Twirlyman
03-11-2012, 08:14 PM
Appreciate the guide Coh3n, I see alot of effort has gone into it! I'm new here so I really want to stop leeching and start becoming involved :)
Thanks! and hopefully you'll see me with my own scripts in the future!

Zockuito
03-15-2012, 03:47 AM
Well guys, I just learned how to loop! :) I have a few cool scripts in mind that I hope to share with you guys! :D Wish me luck! :)

Khaini
03-17-2012, 02:43 PM
Today i decided to try to take part in this community and stop being a leecher, wish me luck:)

wazzzup
03-19-2012, 07:24 AM
Excellent tutorial, got a bit of a headache trying to cram all that knowledge at once but great job!

JamesAOC
04-01-2012, 06:45 PM
Nice! Hard to take it all in it once but I definitely learned a lot. Now I think I'll go read your others.

polska94
04-06-2012, 12:12 PM
Does Simba support scripting in other programming languages, like Python?

TheCandyMan
04-08-2012, 01:22 AM
Awesome tut. I have some python experience so some is easier to grasp, i only have one question as of now.. and it has to deal with the DeclarePlayers procedure...


program DeclarePlayers;
{$DEFINE SMART}
{$i srl/srl.simba}
procedure DeclarePlayers;
begin
HowManyPlayers := 1;
NumberOfPlayers(HowManyPlayers);
CurrentPlayer := 0;
Players[0].Name := 'Main';
Players[0].Pass := 'pass';
Players[0].Nick := 'main';
Players[0].Active := True;
Players[0].Pin := '0000';
end;
begin
Smart_Server := 152;
Smart_Members := False;
Smart_Signed := True;
Smart_SuperDetail := False;
ClearDebug
SetupSRL;
DeclarePlayers;
LoginPlayer;
end.

This is what i get in my debug box:

SRL Compiled in 0 msec
SMART Initialized.
Loaded: Server 152, Members: False, Signed: True, Super Detail: False.
Invalid world number or corrupted world list. Please review your settings
Successfully executed.

For the account info.. i used my real stuff if that matters..

Coh3n
04-09-2012, 02:07 AM
Does Simba support scripting in other programming languages, like Python?Not at this time, no.


Awesome tut. I have some python experience so some is easier to grasp, i only have one question as of now.. and it has to deal with the DeclarePlayers procedure...


program DeclarePlayers;
{$DEFINE SMART}
{$i srl/srl.simba}
procedure DeclarePlayers;
begin
HowManyPlayers := 1;
NumberOfPlayers(HowManyPlayers);
CurrentPlayer := 0;
Players[0].Name := 'Main';
Players[0].Pass := 'pass';
Players[0].Nick := 'main';
Players[0].Active := True;
Players[0].Pin := '0000';
end;
begin
Smart_Server := 152;
Smart_Members := False;
Smart_Signed := True;
Smart_SuperDetail := False;
ClearDebug
SetupSRL;
DeclarePlayers;
LoginPlayer;
end.

This is what i get in my debug box:

SRL Compiled in 0 msec
SMART Initialized.
Loaded: Server 152, Members: False, Signed: True, Super Detail: False.
Invalid world number or corrupted world list. Please review your settings
Successfully executed.

For the account info.. i used my real stuff if that matters..Try changing Smart_Server to a different number.

sweetaffroman
04-09-2012, 09:01 PM
I find it really fun learning another language. Learning this as im learning c++ wich also is a really fun and hard language to learn. Btw great job on the turtorial gonna spend many hours here.

Gillzo
04-09-2012, 09:06 PM
great tut learning alot. hope to put what ive learnt into practice

b_lone
04-15-2012, 04:12 AM
Phew. Well..here I go! Goana FINALLY read this. How long did it take you guys to read? xD I'm afraid I'll read it all and not understand one bit...

ne lg
04-16-2012, 04:31 PM
Dont laugh when i ask this question, because i did manage to get a compiling error on the "easiest scipt ever created"

[Error] (5:1): Unknown identifier 'WriteIn' at line 4
Compiling failed.


Dont want to read on in the guide untill i can understand everything really.


Heres what i wrote:

program I_AM_A_FRIKKEN_BOASS;
procedure WriteInDebugBox;
begin
WriteIn('Sup Nig');
end;
begin
WriteInDebugBox;
end.

I mean, i guess the error means that is doesnt know what "WriteIn" is

Coh3n
04-16-2012, 09:19 PM
It's WriteLn (short for write line), not WriteIn. ;)

SwordBearFis
04-17-2012, 01:56 AM
coh3n you're such a bro! trying to teach myself to write scripts is super hard but your tutorial helped a lot. thanks man!

Saltyspoons
04-17-2012, 04:16 AM
I sat down in keyboarding class and read this entire thing. (very carefully!) I feel like I've learned so much. The format is great and easy to understand for a beginner like me, and it is leaving me hungry for more knowledge! Thanks

kenauto1125
04-27-2012, 09:10 PM
Hey Coh3n your tut rocks man... I just started on this language. I am educated in visual basic and java so I know some of the more basic stuff, but there are very small differences when it comes to SRL! I would like to thank you for your time in making this awesome tut all of your tuts are going to be one of my first refs. When I start my first script! (Don't worry if I run into a problem I will try to figure it out myself first)

Explicit1
04-29-2012, 01:19 AM
I just want to thank you for taking your time in writing this script. You made it very easy to understand for any new script writers, such as myself :).

Megadeth
05-03-2012, 11:42 AM
I'm about to start reading this guide - thank you for providing it. I hope, in time, I can eventually contribute some cool scripts to the community.

squall
05-05-2012, 02:49 PM
Great tutorial, I would like to try scripting. This kinda went over my head but ill still give it a go.

Twisterz
05-05-2012, 04:11 PM
Fantastic tutorial I've been wanting to try writing a script for Simba for a while now and this helps greatly!

Dragonrider
05-06-2012, 01:02 AM
I'm working on this now, I think its great but will take me a few times reading through to understand it.

Chen Monopoly
05-08-2012, 03:22 AM
Neither the Simba wiki nor the SRL wiki work.

Zeta Matt
05-17-2012, 05:48 PM
Just a perfect tutorial! When I was using powerbot and tried to understand scripting in that java tutorials site, I gave up. I couldn't understand a word in that tutorial, everything was strange: boolean, integer, float... But this tutorial did it! Now I understand most of the things I didn't thanks!!!

Zeta Matt
05-24-2012, 02:52 AM
This took me a few months to rewrite, so I wouldn't expect the intermediate guide to be finished anytime soon, since I now have even less time with school and hockey. Nevertheless, enjoy!

Coh3n

Thanks man =D I'm anxious for the intermediate guide; since I learned everything from the begginer easily from this thread :)
By now I'm improvising with the SCAR tutorial =)

cadet54
05-25-2012, 05:18 AM
This is awesome, thanks very much I have been going through other beginners guides on setting up basic scripts, just the woodcutting ones so far but working my way through them, this helps me to understand pascal a little bit more.
Also thanks for the tip on ctrl + space has made function finding easier to.

The7thSoldierX
05-27-2012, 02:08 PM
Thank you for the wonderfully written guide! :)
Hopefully now with all this information I can combine this with the woodcutting guide
by griff to make a fully functional RS script by myself!

Again thanks for the guide, I look forward to reading others by you!

Finally have time off to actually USE my computer and can sit back and do some coding :)

buffalozen
05-30-2012, 04:19 AM
Excellent tutorial: reminds me of much of my past VB experience, save the use of buckets, dear God... buckets - instructor forced class to overuse them, extremely annoying. Past experience - and subsequent PTSD - aside, Pascal proves simplistic enough. Expect to see an avid "scripter" very soon - that is, if my OCD doesn't get carried away with writing anti-bans =I.

SimbaBro
06-01-2012, 12:54 AM
Leggo.

snowfire
06-01-2012, 09:45 PM
ok not sure what im doing wrong but


[Error] (10:3): Unknown identifier 'WriteIn' at line 9
Compiling failed.

and it only happens when i type in the script myself im not sure if i do the spacing wrong or how im supposed to do it. the code im typing is


program Testing;

function GetNumber: Integer;
begin
Result := 10;
end;

begin
WriteIn(IntToStr(GetNumber));
end.

masterBB
06-01-2012, 11:10 PM
It is WriteLn. It is short for Write line. Also in your example the IntToStr isn't needed since WriteLn tries that itself.

snowfire
06-02-2012, 12:37 AM
It is WriteLn. It is short for Write line. Also in your example the IntToStr isn't needed since WriteLn tries that itself.

Ah ok thanks, im just following the guide :P

kyleisaboss
06-03-2012, 04:23 PM
Error: Exception: Access violation at line 101
The following DTMs were not freed: [SRL - Lamp bitmap, 1]
The following bitmaps were not freed: [SRL - Mod bitmap, SRL - Admin bitmap, SRL - Flag bitmap]
PLEASE SOMEONE HELP ME!!!

Abu
06-03-2012, 07:12 PM
Error: Exception: Access violation at line 101
The following DTMs were not freed: [SRL - Lamp bitmap, 1]
The following bitmaps were not freed: [SRL - Mod bitmap, SRL - Admin bitmap, SRL - Flag bitmap]
PLEASE SOMEONE HELP ME!!!

Has been solved many times - if you had any sense you would use the Search Button (http://villavu.com/forum/search.php) before resolving to a hopeless plea in all caps (which is very annoying and an infractable offence)

AcidAlchemy
06-05-2012, 04:56 AM
Time to end my leech hood lol.
This really is an amazing guide. I have a rudimentary understanding of programming and this was a good refresher on the basics. Time to start expirementing >:D.

Poogie
06-12-2012, 12:12 AM
Time to end my leech hood lol.
This really is an amazing guide. I have a rudimentary understanding of programming and this was a good refresher on the basics. Time to start expirementing >:D.

I too decided to end my short amount of leeching. However I have no previous understanding of programming so... I have been staring at the screen stupidly. I am planning to make a script so I will go through this guide as much as possible.

grats
06-12-2012, 12:21 AM
I too decided to end my short amount of leeching. However I have no previous understanding of programming so... I have been staring at the screen stupidly. I am planning to make a script so I will go through this guide as much as possible.

If you're not familiar with programming you should check out yohojo's first video so you can see how the basics work. Then go through this guide and possibly watch the video again & continue with his other vids after that

Master BAW
06-12-2012, 02:33 PM
Thank you for this Tutorial.
This will help me on my way to make my own bot :)

abibot
06-15-2012, 03:36 AM
Thanks so much Coh3n, following this to make my own first script!

skillzmatic
06-15-2012, 04:11 PM
I kinda don't understand these anti leeching things. If you don't want the script to be leeched don't post it in public but members instead?

Abu
06-15-2012, 07:00 PM
I kinda don't understand these anti leeching things. If you don't want the script to be leeched don't post it in public but members instead?

No one wants their script to be leeched, but unfortunately there are users here who just come here for the scripts and never leave feedback on how they can be improved. Shame really.

Also, we want people to actually use and appreciate our scripts. If all the scripts were posted in the SRL Member forum then 70 - 80% of all users here won't have access to any decent scripts at all.

Sure this sites about programming and learning, but you also want to show you're work and what you've achieved by posting it publicly. It's then up to the users to give feedback on the script and post progress reports so the scripter knows his work is being appreciated.

Etrnl Fear
07-27-2012, 06:00 AM
Very nice beginner's tutorial, thanks for the hard work and hours spent making it!

Definitely going to make a few newby scripts and post for feedback. :)

gorouchan
07-31-2012, 02:31 PM
Same with above, and also you spell declaring as declareing :o

lona93
08-01-2012, 07:40 PM
I keep getting smart server errors and don't know why

Stiemsma
08-03-2012, 10:42 PM
Very nice tutorial, thank you. I will refer back to this thread whenever I have any doubts fundamentally.

Etrnl Fear
08-08-2012, 12:26 AM
I think, somewhere in the 'Cases' section, you should add that 'case' functions as a 'begin' and needs an 'end' of its own. Other than that, this guide has cleared up all of my nooby errors. :)

US Marine
09-09-2012, 10:19 AM
You should print this out into book format and sell it. I would buy, going on deployment without internet and I would like to learn while I am gone. :)

Im going to read as much as I can.

l6bustank
09-13-2012, 07:04 PM
Woot! Made my 1st working script!
Thx a ton, Coh3n! :D

rep +1

JaJaBinks
09-23-2012, 06:05 AM
I'd like to begin by mentioning your absolutely phenomenal job on the tutorial. Decided I'd get into it and look at some of the natives. Unfortunately, the wiki appears it was removed. May I ask where I can view the natives?

If applicable, I'd like to avoid having to use something similar to Microsoft's intellisense to figure each function out.

Thanks!



The Simba/SRL Wiki

The Simba Wiki (http://villavu.com/wiki/Simba) is useful for everything Simba related. You don't know exactly what a built-in function does? No problem, just head over to the Simba Wiki and navigate through the menus to where you want to be.


The SRL Wiki is filled with other tutorials that utilize SRL. Before you go running over there, you should know that all the guides were written for SCAR, and they may not work in Simba. Also, they are most likely outdated as the SRL Wiki doesn't get a lot of development. Nonetheless, you can still learn a lot from browsing the SRL Wiki (http://villavu.com/wiki/Main_Page). :)

Coh3n
09-23-2012, 04:57 PM
You should print this out into book format and sell it. I would buy, going on deployment without internet and I would like to learn while I am gone. :)

Im going to read as much as I can.I can convert it to a .pdf fairly easily I think. E: Here you go. :)

http://www.coh3n.com/articles/beginners_simba.pdf

Oh yes, the Wiki was removed some time ago. It has been replaced with SRL Documentation, which you can find here (http://docs.villavu.com/srl-5/). I'll update the tutorial right now. :)

Thanks.

Oh, and note that not every SRL file is in the documentation. They're not all finished; however, all the core files are there.

E: Fixed. There may be other errors as well, so don't be afraid to let me know. :)

Runehack123
10-27-2012, 10:29 AM
Does that mean the intermediate tutorial is released now :) :) ?

This TuT helped me so much feel more comfortable with the basics even though I still have no idea what <> means. I googled it and all but couldn't find anything and you have it in your TuT.
Not even the slightest clue :( ....

riwu
10-27-2012, 10:34 AM
Does that mean the intermediate tutorial is released now :) :) ?

This TuT helped me so much feel more comfortable with the basics even though I still have no idea what <> means. I googled it and all but couldn't find anything and you have it in your TuT.
Not even the slightest clue :( ....
More than or less than (i.e. anything that is not '='), commonly used to compare integers/strings.

>= will be more than or equal to
<= will be less than or equal to

Also he already has an AIO one here: http://villavu.com/forum/showthread.php?t=49089

Coh3n
10-28-2012, 07:33 PM
Does that mean the intermediate tutorial is released now :) :) ?

This TuT helped me so much feel more comfortable with the basics even though I still have no idea what <> means. I googled it and all but couldn't find anything and you have it in your TuT.
Not even the slightest clue :( ....<> means doesn't equal. I'll add that to the guide.

And no, unfortunately the intermediate guide isn't released.

Kobbra
11-07-2012, 10:52 AM
Coh3n, thank you very much for writing this guide, really helped me understand the basics of scripting.

I'd like to ask a question (may sound noobish)

Say for example I was working on a combat script, would I add a constant so that the player's character eats every time its health falls below 300 lifepoints?

Sorry if I didn't explain this right.

Coh3n
11-07-2012, 03:01 PM
I'm assuming you mean to ask how you would do that? In this case, it's actually quite simple. All you would do is set a constant, check the HP level, and if it is below whatever the constant is set to, eat some food.

program new;
{$i srl/srl.simba}

const
MINIMUM_HP = 300;

procedure eatFood();
var
col: string;
begin
if (getMMLevels('hp', col) <= MINIMUM_HP) then
begin
writeln('health is too low, we need to eat!');

// here is where you would put your code of eating the food
end;
end;

begin
end.
I'm not going to do the whole problem for you, but that's how you would use the constant. :) Hopefully that helps.

Kobbra
11-07-2012, 09:51 PM
I'm assuming you mean to ask how you would do that? In this case, it's actually quite simple. All you would do is set a constant, check the HP level, and if it is below whatever the constant is set to, eat some food.

program new;
{$i srl/srl.simba}

const
MINIMUM_HP = 300;

procedure eatFood();
var
col: string;
begin
if (getMMLevels('hp', col) <= MINIMUM_HP) then
begin
writeln('health is too low, we need to eat!');

// here is where you would put your code of eating the food
end;
end;

begin
end.
I'm not going to do the whole problem for you, but that's how you would use the constant. :) Hopefully that helps.

Ah ok, thanks for writing that it helped, and I was asking if using a Constant would be appropriate in a script where you would need to heal.

Coh3n
11-10-2012, 03:51 PM
Using a constant is appropriate whenever you're using the same number twice, or you want the user to set something. So to answer your question, yes it would be appropriate. :)

Nufineek
11-26-2012, 08:53 PM
Hey :) I'm trying to learn scripting from your guide. One of the simplest scripts didn't work for me:

program HeyWorld;

procedure WriteInDebugBox;

begin
WriteIn ('Hey world!');
end;
begin
WriteInDebugBox;
end.

[Error] (6:1): Unknown identifier 'WriteIn' at line 6
Compiling failed.

Can anyone help me?

Coh3n
11-27-2012, 01:30 AM
Hey :) I'm trying to learn scripting from your guide. One of the simplest scripts didn't work for me:

program HeyWorld;

procedure WriteInDebugBox;

begin
WriteIn ('Hey world!');
end;
begin
WriteInDebugBox;
end.

[Error] (6:1): Unknown identifier 'WriteIn' at line 6
Compiling failed.

Can anyone help me?The command is WriteLn, not WriteIn. ;)

Ian
11-27-2012, 01:37 AM
I made the same mistake, the font is misleading :p

Coh3n
11-27-2012, 03:31 AM
I made the same mistake, the font is misleading :pI'll change all the lowercase l's to a capital, just for clarification. :)

E: Done.

Farcefii
11-30-2012, 09:41 AM
Aw yes, high school java knowledge put to use * u *

Thank you very very much for making this tutorial!
now off I go to learn about all the pre-existing functions/procedures

lord victor
12-01-2012, 04:11 PM
Ah, thought that I would try teaching myself Pascal!

At the end of the first few sections there is a program called "PuttingTogetherBasics"
which I completed pretty quickly and thanks to your tutorial understand pretty well :D

I keep getting the following error message though when I go to compile to program:
[Error] C:\Users\takingoutmyuser\Desktop\SRL scripts\Playing With Constants.simba(14:1): Semicolon (';') expected at line 13
Compiling failed.

I've looked over it and it seems to be the same as the sample program, I'm sure I'm just missing something small though!

It might not be clear here but line 13 is this:
procedure HowManyLogs;

If someone could help me out so I can keep moving on that would be awesome.




program PuttingTogetherBasics;
//declaring variables globally
var
Logs: Integer;
Exp: Extended;

//declaring constants
const
NUMBER_OF_LOGS = 500; //notice the integer
TREE_TO_CUT = 'Magic' //notice the string

//using a procedure
procedure HowManyLogs;
begin
Logs :=250
Exp :=195.5

WriteLN('We have chopped' + IntToStr(Logs) + 'logs this session!'
Wait(500);
WriteLn('we want to chop' + IntToStr(NUMBER_OF_LOGS) + 'logs.');
Wait(500);
WriteLn('We are chopping' + TREE_TO_CUT + 'trees!');
Wait(500);
WriteLn('We have gained' + FloatToStr(Logs * Exp) + 'xp this session!');
end;


//float to str converts extended values to strings same as IntToStr

function WeAreBored: string;
var //declaring vars locally
s: String;
begin
Result := 'what are we going to do now?';
s := 'We are very bored chopping all these logs!';
wait(500);
WriteLn(s);
end;

begin
ClearDebug //clears debug box
HowManyLogs;
WriteLn(WeAreBored);
end.

Ashaman88
12-01-2012, 04:26 PM
; after magic

Coh3n
12-02-2012, 08:59 PM
When you get that error message, check the line before the one the error gives you. That's usually the one that's missing a ;.

ringgold101
12-16-2012, 09:13 AM
Thank you so much i'm learning alot I cant wait to make my first rs script :)

tvain
12-30-2012, 06:49 PM
Why is it that "We are very bored chopping all these logs!" gets displayed before "What are we going to do now?" in the debug log for this function:



function WeAreBored: string;
var // Declareing variables locally
s: String;
begin
Result := 'What are we going to do now?'; // Notice that "Result" is a string because the function returns a string
s := 'We are very bored chopping all these logs!';
Wait(500);
WriteLn(s); // Notice no "IntToStr" because the variable "s" is already a string
end;

Gucci
12-30-2012, 10:53 PM
Why is it that "We are very bored chopping all these logs!" gets displayed before "What are we going to do now?" in the debug log for this function:



function WeAreBored: string;
var // Declareing variables locally
s: String;
begin
Result := 'What are we going to do now?'; // Notice that "Result" is a string because the function returns a string
s := 'We are very bored chopping all these logs!';
Wait(500);
WriteLn(s); // Notice no "IntToStr" because the variable "s" is already a string
end;

I believe it's because the WriteLn(s) is called before the function ends and therefore displays s before it displays the functions result

Pod
01-01-2013, 09:46 AM
Thanks for the tutorial! (: shall get scritoing

Coh3n
01-02-2013, 08:33 PM
Why is it that "We are very bored chopping all these logs!" gets displayed before "What are we going to do now?" in the debug log for this function:



function WeAreBored: string;
var // Declareing variables locally
s: String;
begin
Result := 'What are we going to do now?'; // Notice that "Result" is a string because the function returns a string
s := 'We are very bored chopping all these logs!';
Wait(500);
WriteLn(s); // Notice no "IntToStr" because the variable "s" is already a string
end;


I believe it's because the WriteLn(s) is called before the function ends and therefore displays s before it displays the functions result

Yes. When Writeln(WeAreBored); is called, it executes WeAreBored first, then it executes the Writeln. Since Writeln(s) is called in WeAreBored, it is called before the original Writeln. I hope that makes sense.

Smoeltje
01-07-2013, 06:11 PM
Im currently halfway trough the tutorial and I must say it has been a very pleasant read so far!

Xeronate
02-25-2013, 03:08 AM
Thanks so much for writing this tutorial. I took 6 pages of notes on it and am looking forward to actually writing a script. A little disappointed that I still can't write even a noob script, but I can't wait until I can. I'll post the first thing I make!

Ian
02-25-2013, 03:14 AM
Thanks so much for writing this tutorial. I took 6 pages of notes on it and am looking forward to actually writing a script. A little disappointed that I still can't write even a noob script, but I can't wait until I can. I'll post the first thing I make!

Don't worry, the first script is always hard, remember to ask if you get stuck on something :)

Xeronate
02-25-2013, 03:57 AM
Don't worry, the first script is always hard, remember to ask if you get stuck on something :)

I'm getting mixed stimuli from you XD. Well thanks for being willing to help. I'll make sure to keep that in mind. Moving on to YoHoJo's tut right now and then I'll try my own.

Saint//+
02-25-2013, 04:56 AM
very helpful, between this tut and yohojo's i can cut down an entire inv of trees :)

Ian
02-25-2013, 05:59 AM
I'm getting mixed stimuli from you XD. Well thanks for being willing to help. I'll make sure to keep that in mind. Moving on to YoHoJo's tut right now and then I'll try my own.

Sorry if I sent the wrong message earlier, I'm all for people learning to script :)

Fishh
02-25-2013, 06:48 PM
Hey, thanks for making this tutorial, I'm working my way through it. Will this work for the '07 release currently? I'm at the first stage of learning how to make an actual script for RS, implementing DeclarePlayers and SMART. When I try to launch to check if it'll log a character in I get this error:

[Error] (21:3): Unknown identifier 'Smart_Server' at line 20
Compiling failed.

This is the Smart_Server line. I've tried changing the servers around, etc. Still to no avail. Any help would be appreciated, I'd like to get working on some scripts and get into the member area. I've got 3 years of experience with C# but none with Pascal apart from this tutorial.

Thanks!

EDIT: Just read a few topics, I see that a VM is easy to run at the moment than getting SMART to work. I'll just use a VM until SMART is available again.

If anyone has any useful tips for me though in regards to programming in Pascal (specifically for RS scripts) please feel free to send me a PM, I'm incredibly interesting in learning more and want to become a contributing member of this community for high quality scripts. It may take me a while but I'll get there.

tealc
02-25-2013, 07:09 PM
Hey, thanks for making this tutorial, I'm working my way through it. Will this work for the '07 release currently? I'm at the first stage of learning how to make an actual script for RS, implementing DeclarePlayers and SMART. When I try to launch to check if it'll log a character in I get this error:

[Error] (21:3): Unknown identifier 'Smart_Server' at line 20
Compiling failed.

This is the Smart_Server line. I've tried changing the servers around, etc. Still to no avail. Any help would be appreciated, I'd like to get working on some scripts and get into the member area. I've got 3 years of experience with C# but none with Pascal apart from this tutorial.

Thanks!



//SMART_SERVER := 10;
//SMART_MEMBERS := TRUE;
// SMART_SIGNED := TRUE;
// SMART_SUPERDETAIL := FALSE;

SRL_SIXHOURFIX := TRUE;
SMART_FIXSPEED := TRUE;


I believe smart server, members, super detail and signed are for an older version. Just comment it out and add the two lines above. Some functions won't work for '07 check out this thread for the unofficial '07 include http://villavu.com/forum/showthread.php?t=96863.

Fishh
02-25-2013, 07:38 PM
Cheers for the help.

Trying to figure out the changes for editing the SMART params, etc at the moment.

** Failed To Grab Smart Parameters **
** Please check your internet connection/firewall **
Successfully executed.

Getting that at the moment.

Going to keep trying to figure it out.

Coh3n
02-25-2013, 11:08 PM
Hey, thanks for making this tutorial, I'm working my way through it. Will this work for the '07 release currently? I'm at the first stage of learning how to make an actual script for RS, implementing DeclarePlayers and SMART. When I try to launch to check if it'll log a character in I get this error:

[Error] (21:3): Unknown identifier 'Smart_Server' at line 20
Compiling failed.

This is the Smart_Server line. I've tried changing the servers around, etc. Still to no avail. Any help would be appreciated, I'd like to get working on some scripts and get into the member area. I've got 3 years of experience with C# but none with Pascal apart from this tutorial.

Thanks!

EDIT: Just read a few topics, I see that a VM is easy to run at the moment than getting SMART to work. I'll just use a VM until SMART is available again.

If anyone has any useful tips for me though in regards to programming in Pascal (specifically for RS scripts) please feel free to send me a PM, I'm incredibly interesting in learning more and want to become a contributing member of this community for high quality scripts. It may take me a while but I'll get there.Oh, that's outdated! You no longer need those SMART variables. You can load SMART with the following script:

program new;
{$DEFINE SMART}
{$i srl/srl.simba}

begin
SetupSRL();
end.

I will update the first post.

reidcool
03-03-2013, 03:11 AM
This seems simmilar to "Turing"

StickToTheScript
03-03-2013, 03:33 AM
Under AntiBans and AntiRandoms heading, you used the word "think" when I think you meant to put "thing".


AntiRandoms - Procedures/Functions that solve the many RuneScape random events. Don't panic! All the solvable random events are already implimented into SRL. The only think you have to do is add one line of code.

Coh3n
03-03-2013, 07:19 AM
This seems simmilar to "Turing"They are similar, yes.


Under AntiBans and AntiRandoms heading, you used the word "think" when I think you meant to put "thing".Yeah, you're right, thanks. :)

adeghati
03-03-2013, 09:07 PM
Great tut! Very helpful, goes over all the main foundations for learning simba.
Thanks :)

Skritler
03-09-2013, 03:26 AM
Thank you, I'm half way through this and it's helped me a lot so far!

ColdFire
03-12-2013, 10:20 PM
Wow, Thank you so much! What a wonderful tutorial.

brock624
03-15-2013, 09:48 PM
That was an incredibly informative tutorial. This really is THE guide for beginners, thank you for explaining terms and breaking down each line of code. I am looking forward to reaching this level of expertise one day. Thanks again!

tvain
03-26-2013, 07:52 AM
hey Coh3n do you think that you could give us some suggestions on what to read up on/learn after reading this guide? Also do you have some programming excercises/ideas on what we can try and do with what we just learnt?

Coh3n
03-26-2013, 03:56 PM
hey Coh3n do you think that you could give us some suggestions on what to read up on/learn after reading this guide? Also do you have some programming excercises/ideas on what we can try and do with what we just learnt?Well ideally I should have an intermediate and advanced guide to go along with this, but I no longer have the time to do so.

YoHoJo has some great video guides out there. I would start there. He actually teaches how to use your programming skills in Runescape.

Check this one out: http://villavu.com/forum/showthread.php?t=69179

deathcrow
03-26-2013, 04:07 PM
This is a great tutorial. Very nicely done, Coh3n.

tabundule
03-27-2013, 04:01 AM
When i run following script, it open a window and loads runescape, but it doesn't login. ( I also added the red parts, because i have smart8 and the p07Include )

program DeclarePlayers;
{$DEFINE SMART8} // This is how we include SMART; it HAS to be called BEFORE SRL!
{$i srl/srl.simba}
{$I P07Include.Simba}

procedure DeclarePlayers;
begin
HowManyPlayers := 1; // This is set to the total amount of players (more on multiplayer later ;)), for now, just keep it set as 1
NumberOfPlayers(HowManyPlayers); // This is a procedure in SRL which sets up player arrays (also, more on that later), this will always be the same
CurrentPlayer := 0; // This is the player to start with; the first player will always be 0 (you'll find out when you learn all about arrays)

Players[0].Name := ''; // Username
Players[0].Pass := ''; // Password
Players[0].Nick := ''; // 3-4 lowercase letters from username; used for random event detection
Players[0].Active := True; // Set to true if you want to use Player 0
Players[0].Pin := ''; // Leave blank if the player doesn't have a bank pin
end;

begin
ClearDebug;
SetupSRL;
DeclarePlayers; // Calls the procedure, you can't forget this!
LoginPlayer; // You want your player to login, right?
end.

Coh3n
04-02-2013, 02:15 AM
It's likely because (as far as I know) SMART8 is for RS not OSR. I'm not sure if there's a version of SMART that works with OSR.

rj
04-02-2013, 02:22 AM
It's likely because (as far as I know) SMART8 is for RS not OSR. I'm not sure if there's a version of SMART that works with OSR.

8 works with osr

Coh3n
04-02-2013, 03:50 PM
8 works with osrIt would have to be a modified version, though. So the "official" one wouldn't work, he'd still need a different version.

BelgianFries
04-02-2013, 07:58 PM
program IfThenExample;

procedure RandomFunction;
var
i: Integer;
begin
if (Random(10) < 5) then
WriteLn('Less than 5!')
else
WriteLn('Greater than or equal to 5!')

i := Random(1000);
if ((i < 100) or (i>500)) then
begin
WriteLn('Small or large!');
WriteLn('Which is it?');
end else
begin
WriteLn('Somewhere in the middle!');
WriteLn('But where...');
end;
end;

begin
ClearDebug,
RandomFunction;
end.


Error: [Error] (13:3): Semicolon (';') expected at line 12
Compiling failed.



But there's clearly a semicolon there, am I doing something wrong somewhere else in my code? I can't find the mistake.

happy hippo
04-03-2013, 01:32 AM
Bookmarked This Will help me in furer when i try and make my first script

Coh3n
04-03-2013, 02:40 PM
program IfThenExample;

procedure RandomFunction;
var
i: Integer;
begin
if (Random(10) < 5) then
WriteLn('Less than 5!')
else
WriteLn('Greater than or equal to 5!')

i := Random(1000);
if ((i < 100) or (i>500)) then
begin
WriteLn('Small or large!');
WriteLn('Which is it?');
end else
begin
WriteLn('Somewhere in the middle!');
WriteLn('But where...');
end;
end;

begin
ClearDebug,
RandomFunction;
end.


Error: [Error] (13:3): Semicolon (';') expected at line 12
Compiling failed.



But there's clearly a semicolon there, am I doing something wrong somewhere else in my code? I can't find the mistake.
That error refers to the line of code that comes before (not including white spaces) the highlighted line. That should help. :)

Also, you can use [SIMBA][ /SIMBA] (without the space) tags to post Simba code.

BelgianFries
04-03-2013, 02:58 PM
That error refers to the line of code that comes before (not including white spaces) the highlighted line. That should help. :)

Also, you can use [SIMBA][ /SIMBA] (without the space) tags to post Simba code.

Oh, haha. Silly mistake. I actually already finished your tutorial, but thanks anyway. :p

Petite One
04-20-2013, 12:08 AM
program WhileDoExample;

procedure WhileDoExample;
var
count: Integer;
begin
while (Count <> 5) do // See how the condition is the opposite of what you want? You want the script to end when Count = 5, so while Count doesn't equal 5, do this (<> means "doesn't equal")
begin
Inc(Count);
Wait(500);
WriteLn('The count is ' + IntToStr(Count) + '.');
end;
end;

begin
ClearDebug;
WhileDoExample;
end.

I see that Count is undeclared. Does this mean that an undeclared integer takes the value of 0 ?

Coh3n
04-20-2013, 12:22 AM
Yes, it does. Count is declared as an integer and it's initial value is set to zero.

Aph0tix
04-20-2013, 01:22 AM
So excited to get home and try this out!

phat808
05-06-2013, 08:50 AM
Thanks a lot for your hard work on this guide. It really helped me understand this language more. I first was inspired to learn this language 1) because I wanted to know how to fix and edit existing scripts to fit my needs, and also eventually make my own scripts and give back to the community.

Thanks again,
Phat808

Goatchees
05-30-2013, 07:24 AM
mHOW long will it take till i can make simba scripts >_> I wanna make a barb agility 9_9, A fisher, TRee chopper and banker 6_6. I understand the loops i mean i cant write them but by reading it I understand everything of the information that you stated.