SRL Archive - OSR Beginner Scripting Tutorials

THE Beginner's Simba Tutorial


Coh3n

2010-09-13 00:08:09

THE Beginner's Tutorial
This tutorial was last updated on September 23rd, 2012.


Introduction
[INDENT]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. 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 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! 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[/INDENT]


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
[INDENT]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.


The Basic Types
  • This was taken straight out of the SCAR Manual, I couldn't have explained it better myself.

Procedures and Functions
  • Procedures and functions 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;
    1. 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"..
    2. 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).
    3. 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.
    4. 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 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 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 can be declared in two different ways:
    1. 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.
    2. 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
[/INDENT]


Standards
[INDENT]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:
  1. 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.
  2. 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. ;)
  3. The begin statement appears on its own line, and end statement always matches the begin statement by columns. For example:

  4. 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.
  5. 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).
  6. Try not to combine two or more statements on one line. Each statement gets it's own line.

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

    // Good
    if (Condition) then
    DoThis;

    if (Condition) then
    begin
    DoThis;
    DoThat;
    end;
  8. 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:

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

    // Good
    i := (5 * 4 + 3);
    HowManyLogs(1, 5, 10);
  10. You should never have a white space on the inside of parenthesis. Example:

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

    // Good
    if (i = 100) or (k = 50) then
    DoThis(DoThat);
  12. 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. :)
  13. The names of procedures and functions should always begin with a capital letter and be camel-capped (i.e. Pascal case) for easier readability. Example:

  14. // Bad
    procedure walktobank;

    // Good
    procedure WalkToBank;
  15. 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.
  16. 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). 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).

    • 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.
  17. Where possible, parameters/variables of the same type should be combined into one statement. For example:

  18. // 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;
  19. Boolean variable names must be descriptive enough so that their meanings of True and False values will be clear.

  20. // Bad
    var
    b: Boolean;

    // Good
    var
    DoesBank: Boolean;
  21. When you declare a variable, they are put on the next line after the var statement, and are indented. Example:

  22. // Bad
    var Logs: Integer;

    // Good
    var
    Logs: Integer;
  23. Try to declare variables locally as much as possible to avoid confusion within the script.
  24. 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
[/INDENT]


Scripting Tips/Hints
[INDENT]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.
  • 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.
  • 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.

Simba and SRL Documentation
  • The Simba Documentation 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.

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:

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 (yes, it's for SCAR, so not everything will work in Simba).
[/INDENT]


Programming Statements
[INDENT]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…
  • From: SCAR Manual

    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
    • From: Nava2
      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:
      1. 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.
      2. 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?
      3. 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. 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). 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:

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.
[/INDENT]


The SRL Include
[INDENT]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. :)
[/INDENT]


DeclarePlayers & S.M.A.R.T.
[INDENT]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:
[/INDENT]


Failsafes
[INDENT]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:
  1. MS - Main Screen - The main RuneScape playing screen.
  2. MM - MiniMap - The RuneScape minimap in the top right corner of the RS screen.
  3. MI - Main Inventory - You inventory box on the right of the RS window, below the minimap.
  4. MC - Main Chat - The RS Chat box at the bottom on the RS window.
  5. MB - Main Bank - The RS bank.
  6. 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. :)[/INDENT]


Antiban and AntiRandoms
[INDENT]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. ;)
[/INDENT]


Conclusion
[INDENT]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. I hope this helped you learn the basics of programming. :)

Cheers,
Coh3n[/INDENT]

Coh3n

2010-09-13 00:09:12

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

2010-09-13 00:35:57

you and your tuts coh3n… excellent job, i'll have a better look-see over it later =)

Craig`

2010-09-13 02:19:26

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?

2010-09-13 03:11:42

Terrific job. Too bad I can't give you a second Tutorial writers cup. :)

Gu3st...

2010-09-13 03:15:04

OMF… Wow.. Great job as always! Rep++ :)

HyperSecret

2010-09-13 06:11:57

Very nice Cohen!

Coh3n

2010-09-13 13:21:00

From: Craig`
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.

From: Wizzup?
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

2010-09-13 13:33:04

Very nice, very nice indeed

DeSnob

2010-09-13 21:57:37

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

2010-09-13 22:05:56

From: DeSnob
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

2010-09-15 03:01:10

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

2010-09-15 13:34:10

From: squancy
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

2010-09-25 22:37:16

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

2010-09-26 02:07:05

From: dhandley12
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

2010-09-26 02:41:07

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

2010-09-28 10:23:14

From: Dgby714
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

2010-09-28 11:17:35

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

2010-09-28 13:58:38

From: BraK
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

2010-09-28 15:11:49

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

2010-09-28 15:15:14

From: BraK
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

2010-09-28 15:25:48

Beautifully done Coh3n! It is nice, clean, intuitive. You and your tuts.. Well done good sir, well done.

Coh3n

2010-10-27 02:04:52

From: anonymity
Beautifully done Coh3n! It is nice, clean, intuitive. You and your tuts.. Well done good sir, well done.

Thanks anonymity. :)

Red Fuel Tank

2010-10-30 12:06:25

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

2010-10-30 13:03:12

Great this has helped me loads, thanks.
From: Coh3n
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

2010-10-30 17:36:26

From: Red Fuel Tank
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. :(

From: Troll Man
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

2010-11-06 19:34:53

Great intro to programming, covered alot of basics as well as the specific RS ones.

Thanks alot :)

the smith400

2010-11-10 20:24:55

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

2010-11-10 20:29:22

the smith400, you would do something like this


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

Runescape Pro

2010-11-10 20:40:08

Wouldn't this also work(?):

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

the smith400

2010-11-10 20:48:57

From: Runescape Pro
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

2010-11-10 20:56:35

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

2010-11-10 20:58:01

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

2010-11-10 21:24:50

From: Runescape Pro
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

2010-11-29 16:45:32

iTS VERRY HARD!!!!

WT-Fakawi

2010-11-30 15:19:05

[offtopic]
From: otavioafm
iTS VERRY HARD!!!!
Yes it is. But you will get there, and once you do, there is nothing going to stop you!

[/offtopic]

tofurocks

2011-02-14 19:35:59

Great tutorial, thanks.
Very to the point :)

Santa

2011-03-20 14:33:31

Dude this has so much information! Great guide.. thanks sooo much :)

Baked0420

2011-03-21 16:56:02

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

2011-03-21 18:01:48

Wow gotta change my script …

Coh3n

2011-03-21 18:40:09

From: Baked0420
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

2011-04-11 16:16:41

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

2011-05-27 18:48:03

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

2011-05-27 19:02:28

From: I am new
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

2011-05-27 19:41:10

There You go

masterBB

2011-05-28 09:38:43

From: I am new
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

2011-05-28 10:17:39

Thank you very much :D

Coh3n

2011-05-28 14:37:12

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

2011-05-28 15:58:28

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

2011-05-28 17:23:01

From: I am new
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

2011-05-28 17:36:26

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

2011-05-28 17:41:18

From: I am new
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

2011-07-03 11:14:03

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

2011-07-04 06:50:06

From: blother
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

2011-07-13 23:06:04

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

2011-07-15 08:25:04

From: catbat78
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
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.

BraK

2011-07-15 08:32:35

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

2011-07-15 17:05:59

From: Coh3n
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

2011-07-15 17:57:21

From: catbat78
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

2011-08-10 13:06:33

It's nice and currently up to date. Thank you.

Jupiter

2011-08-15 16:55:15

This is extremely helpful. Thank you so much :)

sf411

2011-09-14 18:40:56

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

2011-09-14 19:38:21

From: sf411
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

2011-09-14 21:06:35

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

2011-11-09 14:48:17

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

2011-11-09 15:22:13

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

2011-11-09 15:37:09

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

2011-11-09 15:39:04

From: beleeive
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

2011-11-09 15:40:37

Also, if you ever have any questions, you can either ping me on IRC or shoot me a PM :)

beleeive

2011-11-09 16:09:20

From: Coh3n
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

2011-11-10 01:53:42

From: beleeive
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
Well 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

2011-11-20 01:32:06

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

2011-11-22 17:25:22

Shouldn't this be stickied as well?

Coh3n

2011-11-22 17:53:05

It should have always been stickied.

NexPB

2011-12-04 11:40:52

great guide, learned alot from it. Hoping to write some great script in the future.

Tempt

2011-12-06 05:59:55

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

2011-12-06 15:35:24

From: Tempt
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

2011-12-09 15:06:30

@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

2011-12-09 15:25:56

From: oudshoorn
@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

2011-12-10 07:44:03

Thanks for the guide, explained really well :)

minnie

2011-12-10 20:12:32

This really helped me out,thank you!

c00ty

2011-12-10 22:31:55

Thank man, this tutorial is perfect. It helped me out so much. I am going to move onto intermediate soon.

Rambot

2011-12-11 05:12:24

"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

2011-12-11 13:21:16

Thanks for the guide! Going to read all trough it in the next few days ^^

Coh3n

2011-12-11 13:26:27

From: Rambot
"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

2011-12-13 22:41:15

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

2011-12-14 08:09:55

Thanks I did the whole guide took a few days, I can't even imagine how long it took to write.

eXoTiK

2011-12-14 16:02:47

Last updated on my birthday, lolol win.

rswiz

2011-12-18 07:04:02

lol, too complex for me… looks like i won't be a member on here for a while =/

lilcmp1

2011-12-20 11:16:13

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

2011-12-21 12:07:52

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

2011-12-21 12:08:16

"WriteLn". Not "WriteIn".

Gaston7eze

2011-12-21 12:13:57

From: RISK
"WriteLn". Not "WriteIn".


Ohh,mLOL,Thanks bro!

Gaston7eze

2011-12-21 12:17:36

program new;
Procedure WritelnDebugBox;
Writeln('Hello')
begin
end.

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

RISK

2011-12-21 12:19:52

Procedure WritelnDebugBox;
begin
Writeln('Hello');
end.

Gaston7eze

2011-12-21 12:47:41

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

RISK

2011-12-21 12:48:33

It's a variable that holds a number.

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

Gaston7eze

2011-12-21 12:56:03

From: RISK
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

2011-12-21 13:11:19

From: Gaston7eze
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

2011-12-21 13:32:17

From: TheJokester117
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

2011-12-26 19:43:53

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

2011-12-30 13:02:51

thanks Coh3n!

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

Everything makes a lot more sense now.

Coh3n

2011-12-30 21:46:46

From: CreaShun
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

2011-12-30 21:55:22

From: Coh3n
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

2011-12-30 21:57:54

From: Yago
The alphabet… i,j,k,l

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

Yush Dragon

2012-01-06 21:07:05

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

2012-01-07 10:48:10

Thanks Coh3n for the great tutorial, helped me a lot!
Keep up the good work :)

plekter

2012-01-12 18:29:50

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

2012-01-12 19:38:36

From: plekter
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

2012-01-12 21:06:27

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

2012-01-12 21:24:52

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

2012-01-14 20:59:27

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

2012-01-14 21:00:14

It's because the guide was not created during SRL5. :)

Grognak

2012-01-14 21:04:31

Ah, that makes a great deal of sense. Had to Google a bit for that, haha.

Goon

2012-01-15 18:28:01

Thanks for the tut hopefully going to start my first script soon once i learn the basics of simba :)

Foo-Fighter

2012-01-16 12:57:34

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

2012-01-18 16:29:56

thanks for the guide i hope ill become a good scripter.

momotron

2012-01-18 19:48:29

Oh damn. I think i may have found myself a new hobby… and 10 days before an exam as well!!! Great guide :')

begginer

2012-01-20 17:38:16

Those taught me some good things

Thanks

C3NTRIX5

2012-01-21 01:15:01

Thank you very much Coh3n. This is the beginning of my scripting career!

usb1y

2012-01-23 00:22:44

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

2012-01-23 17:28:50

From: usb1y
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
You have to include it like

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

joehartwig

2012-01-26 13:35:33

i am a noob at scripting so much help would be greatly appreciated

Coh3n

2012-01-26 17:14:46

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

2012-01-29 02:38:44

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

2012-02-01 05:29:00

hey coh3n nice guide :D
but where can i find the advanced guide? cuase i cant find it :(

thank you

slakan

2012-02-01 08:00:29

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

2012-02-01 08:25:52

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

2012-02-01 08:31:11

From: imscaredtolosemymain
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

2012-02-01 08:41:35

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

2012-02-01 10:19:58

Haha, nei hedmark :)

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

MSN? face?

[email]slakan_91@hotmail.com[/email] add me

imscaredtolosemymain

2012-02-01 11:02:14

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

2012-02-01 14:17:40

From: jouri1333
hey coh3n nice guide :D
but where can i find the advanced guide? cuase i cant find it :(

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

From: imscaredtolosemymain
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. 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

2012-02-01 14:59:01

thanks Coh3n, thats exactly what i was looking for.

Dan the man

2012-02-10 08:46:16

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

2012-02-15 23:25:30

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

2012-02-16 21:13:38

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

2012-02-16 21:55:08

From: crazy5150
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.

From: drfreshtacular
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

2012-02-18 11:55:36

This helped me a lot! I'll be starting my first script soon.

Rezozo

2012-02-18 19:12:04

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

2012-02-19 08:49:11

Good work, nice guide there.
I hope you make the intermediate guide as soon as possible :)

tutkubakay

2012-02-21 17:26:15

thank you i read all

joshj

2012-02-23 18:17:42

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

2012-02-24 01:37:57

From: joshj
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

2012-03-02 01:11:44

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

2012-03-10 20:14:59

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

2012-03-10 22:04:14

Starting to get it xD Thank you so much for doing this!

Coh3n

2012-03-11 04:27:51

I don't think the SRL Wiki exists anymore. That may be why the link doesn't work. :p

Twirlyman

2012-03-11 16:14:18

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

2012-03-14 23:47:51

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

2012-03-17 10:43:11

Today i decided to try to take part in this community and stop being a leecher, wish me luck:)

wazzzup

2012-03-19 03:24:31

Excellent tutorial, got a bit of a headache trying to cram all that knowledge at once but great job!

JamesAOC

2012-04-01 14:45:54

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

2012-04-06 08:12:16

Does Simba support scripting in other programming languages, like Python?

TheCandyMan

2012-04-07 21:22:04

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

2012-04-08 22:07:31

From: polska94
Does Simba support scripting in other programming languages, like Python?
Not at this time, no.

From: TheCandyMan
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

2012-04-09 17:01:12

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

2012-04-09 17:06:09

great tut learning alot. hope to put what ive learnt into practice

b_lone

2012-04-15 00:12:14

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

2012-04-16 12:31:10

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

2012-04-16 17:19:44

It's WriteLn (short for write line), not WriteIn. ;)

SwordBearFis

2012-04-16 21:56:17

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

2012-04-17 00:16:55

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

2012-04-27 17:10:45

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

2012-04-28 21:19:11

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

2012-05-03 07:42:15

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

2012-05-05 10:49:23

Great tutorial, I would like to try scripting. This kinda went over my head but ill still give it a go.

Twisterz

2012-05-05 12:11:08

Fantastic tutorial I've been wanting to try writing a script for Simba for a while now and this helps greatly!

Dragonrider

2012-05-05 21:02:43

I'm working on this now, I think its great but will take me a few times reading through to understand it.

Chen Monopoly

2012-05-07 23:22:03

Neither the Simba wiki nor the SRL wiki work.

Zeta Matt

2012-05-17 13:48:58

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

2012-05-23 22:52:47

From: Coh3n
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

2012-05-25 01:18:21

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

2012-05-27 10:08:43

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

2012-05-30 00:19:34

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

2012-05-31 20:54:58

Leggo.

snowfire

2012-06-01 17:45:02

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

2012-06-01 19:10:34

It is WriteLn. It is short for Write line. Also in your example the IntToStr isn't needed since WriteLn tries that itself.

snowfire

2012-06-01 20:37:18

From: masterBB
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

2012-06-03 12:23:52

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

2012-06-03 15:12:37

From: kyleisaboss
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 before resolving to a hopeless plea in all caps (which is very annoying and an infractable offence)

AcidAlchemy

2012-06-05 00:56:52

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

2012-06-11 20:12:15

From: AcidAlchemy
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

2012-06-11 20:21:05

From: Poogie
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

2012-06-12 10:33:11

Thank you for this Tutorial.
This will help me on my way to make my own bot :)

abibot

2012-06-14 23:36:04

Thanks so much Coh3n, following this to make my own first script!

skillzmatic

2012-06-15 12:11:02

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

2012-06-15 15:00:35

From: skillzmatic
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

2012-07-27 02:00:28

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

2012-07-31 10:31:18

Same with above, and also you spell declaring as declareing :o

lona93

2012-08-01 15:40:05

I keep getting smart server errors and don't know why

Stiemsma

2012-08-03 18:42:57

Very nice tutorial, thank you. I will refer back to this thread whenever I have any doubts fundamentally.

Etrnl Fear

2012-08-07 20:26:40

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

2012-09-09 06:19:07

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

2012-09-13 15:04:11

Woot! Made my 1st working script!
Thx a ton, Coh3n! :D

rep +1

JaJaBinks

2012-09-23 02:05:38

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!

From: Coh3n

The Simba/SRL Wiki
  • The Simba Wiki 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. :)

Coh3n

2012-09-23 12:57:16

From: Usmarine
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. 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

2012-10-27 06:29:46

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

2012-10-27 06:34:58

From: Runehack123
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

2012-10-28 15:33:36

From: Runehack123
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

2012-11-07 05:52:59

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

2012-11-07 10:01:24

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

2012-11-07 16:51:15

From: Coh3n
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

2012-11-10 10:51:40

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

2012-11-26 15:53:21

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

2012-11-26 20:30:25

From: Nufineek
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

2012-11-26 20:37:32

I made the same mistake, the font is misleading :p

Coh3n

2012-11-26 22:31:41

From: BMWxi
I made the same mistake, the font is misleading :p
I'll change all the lowercase l's to a capital, just for clarification. :)

E: Done.

Farcefii

2012-11-30 04:41:27

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

2012-12-01 11:11:24

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

2012-12-01 11:26:51

; after magic

Coh3n

2012-12-02 15:59:46

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

2012-12-16 04:13:28

Thank you so much i'm learning alot I cant wait to make my first rs script :)

tvain

2012-12-30 13:49:06

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

2012-12-30 17:53:49

From: tvain
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

2013-01-01 04:46:24

Thanks for the tutorial! (: shall get scritoing

Coh3n

2013-01-02 15:33:33

From: tvain
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;


From: Gucci
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

2013-01-07 13:11:11

Im currently halfway trough the tutorial and I must say it has been a very pleasant read so far!

Xeronate

2013-02-24 22:08:44

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

2013-02-24 22:14:32

From: Xeronate
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

2013-02-24 22:57:19

From: BMWxi
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//+

2013-02-24 23:56:50

very helpful, between this tut and yohojo's i can cut down an entire inv of trees :)

Ian

2013-02-25 00:59:03

From: Xeronate
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

2013-02-25 13:48:42

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

2013-02-25 14:09:11

From: Fishh
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

2013-02-25 14:38:50

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

2013-02-25 18:08:51

From: Fishh
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

2013-03-02 22:11:30

This seems simmilar to "Turing"

StickToTheScript

2013-03-02 22:33:38

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

2013-03-03 02:19:39

From: reidcool
This seems simmilar to "Turing"
They are similar, yes.

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

adeghati

2013-03-03 16:07:11

Great tut! Very helpful, goes over all the main foundations for learning simba.
Thanks :)

Skritler

2013-03-08 22:26:29

Thank you, I'm half way through this and it's helped me a lot so far!

ColdFire

2013-03-12 18:20:20

Wow, Thank you so much! What a wonderful tutorial.

brock624

2013-03-15 17:48:48

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

2013-03-26 03:52:56

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

2013-03-26 11:56:40

From: tvain
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

2013-03-26 12:07:42

This is a great tutorial. Very nicely done, Coh3n.

tabundule

2013-03-27 00:01:56

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

2013-04-01 22:15:50

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

2013-04-01 22:22:15

From: Coh3n
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

2013-04-02 11:50:41

From: RJJ95
8 works with osr
It would have to be a modified version, though. So the "official" one wouldn't work, he'd still need a different version.

BelgianFries

2013-04-02 15:58:09

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

2013-04-02 21:32:50

Bookmarked This Will help me in furer when i try and make my first script

Coh3n

2013-04-03 10:40:18

From: BelgianFries
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
(without the space) tags to post Simba code.

BelgianFries

2013-04-03 10:58:38

From: Coh3n
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
(without the space) tags to post Simba code.


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

Petite One

2013-04-19 20:08:29

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

2013-04-19 20:22:55

Yes, it does. Count is declared as an integer and it's initial value is set to zero.

Aph0tix

2013-04-19 21:22:54

So excited to get home and try this out!

phat808

2013-05-06 04:50:47

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

2013-05-30 03:24:55

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.

rj

2013-05-30 15:14:55

From: Goatchees
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.


Just read up on some tutorials, is varies from person to person. Start small and then learn more and more complicated stuff

Goatchees

2013-05-31 00:01:23

Can a pro make a script that does hunter and alchs while it waits? im talking runescape

Rotcrack

2013-06-03 14:38:20

Thanks, I found this really helpful!

Kevin

2013-06-03 14:56:49

From: Goatchees
Can a pro make a script that does hunter and alchs while it waits? im talking runescape


It would depend on what was being hunted and how dedicated the scripter was.

Dezval

2013-06-07 19:15:22

Thank you!! This guide was very helpful to me :D

Maxed Red

2013-06-11 08:47:42

I just saw this tutorial and I was wondering if you could re upload the link to the PDF, it would be a lot easier for me if i had the PDF version. If not it's fine.

azzamate

2013-07-27 00:43:31

From: Officer Barbrady
Just read up on some tutorials, is varies from person to person. Start small and then learn more and more complicated stuff


Hey, I'm kinda new but can understand really well and follow instructions, Basically I am going to write a test script for chopping a magic tree but I have found the Color Tolerance Code unreliable so I have decided to follow your method on creating a new font. I so far just created only two letters from my desired object which is Magic Tree, the two letters I have created are a,g, both lowercase saved with correct numbers according to your chart. Now I was wondering how can I use them now that they are in the folder 'sgUpChars'

edtor

2013-07-29 06:04:21

Came back to villavu after a while and this tutorial helped me refresh my scripting knowledge :D

rj

2013-07-29 09:49:29

From: azzamate
Hey, I'm kinda new but can understand really well and follow instructions, Basically I am going to write a test script for chopping a magic tree but I have found the Color Tolerance Code unreliable so I have decided to follow your method on creating a new font. I so far just created only two letters from my desired object which is Magic Tree, the two letters I have created are a,g, both lowercase saved with correct numbers according to your chart. Now I was wondering how can I use them now that they are in the folder 'sgUpChars'


Sorry for the late response:
"stringvariable here := GetTextAtExWrap(x1, y1, x2, y2, minspacing, maxspacing, hsspacing, Color, tolerance, 'sgUpChars');"

for minspacing put 0, and for maxspacing I put 7, and for hsspacing i put 1

Are you making a font set for silabgarza?

azzamate

2013-07-30 02:05:28

From: Officer Barbrady
Sorry for the late response:
"stringvariable here := GetTextAtExWrap(x1, y1, x2, y2, minspacing, maxspacing, hsspacing, Color, tolerance, 'sgUpChars');"

for minspacing put 0, and for maxspacing I put 7, and for hsspacing i put 1

Are you making a font set for silabgarza?


Yes I am :P

rj

2013-07-30 10:31:40

From: azzamate
Yes I am :P


Ok, let me load up the server and see if my font from SS works and if it does I'll upload them here so you can use it (no use in making 60 chars eh?)

@azzamate Ok here you go this should return the uptext:

function sg_GetUpText(tol:Integer): String;
Var
Colors:TIntegerArray;
i:Integer;
begin
// white, blue, yellow, orange, green
// Colors := [16776960, 16777215, 65535, 4161758, 384517];
// 20 tol is decent
Colors := [13948116, 13750794, 645593, 4161758, 384517];
for i:=0 to high(Colors) do
Result := Result + GetTextAtExWrap(9, 9, 231, 18, 0, 8, 1, Colors[i], tol, 'SSUpChars');
end;

Extract SSUpchars to C:/Simba/fonts

Example test script:

{$I SRL/SRL.Simba}
function sg_GetUpText(tol:Integer): String;
Var
Colors:TIntegerArray;
i:Integer;
begin
// white, blue, yellow, orange, green
// Colors := [16776960, 16777215, 65535, 4161758, 384517];
// 20 tol is decent
Colors := [13948116, 13750794, 645593, 4161758, 384517];
for i:=0 to high(Colors) do
Result := Result + GetTextAtExWrap(9, 9, 231, 18, 0, 8, 1, Colors[i], tol, 'SSUpChars');
end;

begin
ActivateClient;
wait(1500);
writeln(sg_getupText(25));
end.

Zealon

2013-07-30 15:47:38

Great guide it's been very helpful getting started, thank you very much

azzamate

2013-07-31 00:18:41

From: Officer Barbrady
Ok, let me load up the server and see if my font from SS works and if it does I'll upload them here so you can use it (no use in making 60 chars eh?)

@azzamate Ok here you go this should return the uptext:

function sg_GetUpText(tol:Integer): String;
Var
Colors:TIntegerArray;
i:Integer;
begin
// white, blue, yellow, orange, green
// Colors := [16776960, 16777215, 65535, 4161758, 384517];
// 20 tol is decent
Colors := [13948116, 13750794, 645593, 4161758, 384517];
for i:=0 to high(Colors) do
Result := Result + GetTextAtExWrap(9, 9, 231, 18, 0, 8, 1, Colors[i], tol, 'SSUpChars');
end;

Extract SSUpchars to C:/Simba/fonts

Example test script:

{$I SRL/SRL.Simba}
function sg_GetUpText(tol:Integer): String;
Var
Colors:TIntegerArray;
i:Integer;
begin
// white, blue, yellow, orange, green
// Colors := [16776960, 16777215, 65535, 4161758, 384517];
// 20 tol is decent
Colors := [13948116, 13750794, 645593, 4161758, 384517];
for i:=0 to high(Colors) do
Result := Result + GetTextAtExWrap(9, 9, 231, 18, 0, 8, 1, Colors[i], tol, 'SSUpChars');
end;

begin
ActivateClient;
wait(1500);
writeln(sg_getupText(25));
end.



Where is the link to download your font by the way?

Edit: Nevermind I just downloaded it from your stall theiver, Whats your username on it maybe I can add you lol

MrBotter22

2013-08-11 23:33:28

Just finished this beginner's tutorial and it was very insightful. Thank you very much! Will continue on to the Intermediate one.

alltehsmallthings

2013-09-15 23:48:46

It's probably just me but i'm having a hard time learning this.

Sjoe

2013-09-16 00:51:24

From: alltehsmallthings
It's probably just me but i'm having a hard time learning this.


I had too, had to read this like 3 times before I understand it :) So keep calm, take breaks. And stay motivated!

Nufineek

2013-10-12 06:00:11

Why do I get this error while tryig the 3rd example in beginner's part ("putting it all together")?

Exception in Script: Duplicate declaration "Exp" at line 6, column 15

EDIT: It works when I change "Exp" variable to for example "Exps". But why Exp didn't work?

bonsai

2013-10-12 08:18:48

From: Nufineek
Why do I get this error while tryig the 3rd example in beginner's part ("putting it all together")?

Exception in Script: Duplicate declaration "Exp" at line 6, column 15

EDIT: It works when I change "Exp" variable to for example "Exps". But why Exp didn't work?


It looks like exp() has been added to the language since this was written.

I couldn't find it in the docs but I wrote a program and googled the results.

It's returning the 'exponential growth' of a number.

program new;
var i : integer ;
j : extended;
begin

for i := 1 to 10 do
begin
j := exp(i);
writeln(j);
end;
end.


Returning:

2.71828182845905
7.38905609893065
20.0855369231877
54.5981500331442
148.413159102577
403.428793492735
1096.63315842846
2980.95798704173
8103.08392757538
22026.4657948067

Googled:

http://www.systemdynamics.org/DL-IntroSysDyn/exgr.htm

Coh3n

2013-10-13 19:13:10

From: Nufineek
Why do I get this error while tryig the 3rd example in beginner's part ("putting it all together")?

Exception in Script: Duplicate declaration "Exp" at line 6, column 15

EDIT: It works when I change "Exp" variable to for example "Exps". But why Exp didn't work?
Glad you caught this. It indeed wasn't built into Simba when I wrote the guide. I'll fix that right now. :)

Aph0tix

2013-10-14 14:23:10

Is this updated for SRL 6?

Coh3n

2013-10-15 12:20:37

From: Aph0tix
Is this updated for SRL 6?
No, it is not; however, there aren't many SRL commands in the guide; it's mostly programming concepts. I will hopefully have time soon to go through and update it for Lape and SRL-6, but I'm not sure if/when that will be.

grasshopper1494

2013-11-04 16:33:40

Great guide, will help me in the future!

CRASH_OVERRIDE

2013-11-05 01:03:59

From: Coh3n
No, it is not; however, there aren't many SRL commands in the guide; it's mostly programming concepts. I will hopefully have time soon to go through and update it for Lape and SRL-6, but I'm not sure if/when that will be.


Wicked. So no ETA on all of this?

Coh3n

2013-11-05 02:09:37

From: tasmania
Wicked. So no ETA on all of this?
I have no idea, sorry. I have a lot of real life stuff keeping me busy. I wouldn't expect it anytime soon, unfortunately.

lollol012

2014-02-03 06:35:19

Huge thanks for this guide. I'd rep you twice if I could.

Chrispyme

2014-03-31 12:42:32

So I have a question, which I'm sure I'll learn later on but am just curious. I understand how the syntax works etc etc but the only thing in curious of, which I'm sure I'll learn later just want a brief description of, is how does sima know what a maple log is? A yew log? How does it know what a bank is, how does it know what the in game items are? What references the code to these particular items? The physical items ingame? Or when the inv is full etc etc

EDIT: I looked at table of contents on next tutorial :) lol

GeezerToad

2014-04-17 13:31:16

Thank you Coh3n for the tutorial. I have started to code myself. Good luck to those who are just starting out.

hakishakataki

2014-04-18 17:18:03

found a spelling error

an 'is' that should be 'it'



at the beginning of the tut

"and run IS as you please"

JSmooth

2014-07-24 22:46:41

The pdf download link for this tutorial is broken by the way. I don't need it just thought I'd let people know.

Coh3n

2014-07-25 08:50:43

From: JSmooth
The pdf download link for this tutorial is broken by the way. I don't need it just thought I'd let people know.
Thanks, I'll add that to my to-do list. I've removed the link for now.

SRLnoob

2014-11-27 01:38:28

I'm not seeing the images for this tutorial. Just an image that says "click and discover imageshack" but when I click on it nothing happens.

Coh3n

2014-12-06 13:17:01

From: SRLnoob
I'm not seeing the images for this tutorial. Just an image that says "click and discover imageshack" but when I click on it nothing happens.


Thank you for pointing this out; they must have expired on ImageShack. I've updated the links. :)

Andrmolja

2015-04-08 10:37:40

In sript
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.
Open Simba/Scripts/TestFile.txt and a notepad file should open that looks something like this: Test!

I need looks something like this: Test! Test! Test! Test! Test! Test! Test! Test!…

For example: X := 123456…n, I need Write to file X-time string Test!

yourule97

2015-04-08 10:48:27

From: Andrmolja
In sript
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.
Open Simba/Scripts/TestFile.txt and a notepad file should open that looks something like this: Test!

I need looks something like this: Test! Test! Test! Test! Test! Test! Test! Test!…

For example: X := 123456…n, I need Write to file X-time string Test!


Here's some code that might help you. I'm not used to using for loops in Simba because I prefer Java, but I think that repeat loops are good enough. If you have trouble following the code, just let me know.

program TryExceptFinallyExample;
var
input : string;
x, i : integer;

(**
* 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;
//EDIT THIS
x := 5;
//END EDIT
i := 0;
input := '';
repeat
input := input + 'Test!';
inc(i);
until i >= x;

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

Andrmolja

2015-04-08 12:36:38

Thank you. It's ok, but I wantto keep the previous string. When restart, click on "Run", I want to keep the old strings. TEST! TEST! TEST! TES TEST! When I start again RUN, I want to have a TEST! TEST! TEST! TES TEST! TEST! TEST! TEST! TES TEST! Please, help?

KeepBotting

2015-04-08 12:45:44

From: Andrmolja
Thank you. It's ok, but I wantto keep the previous string. When restart, click on "Run", I want to keep the old strings. TEST! TEST! TEST! TES TEST! When I start again RUN, I want to have a TEST! TEST! TEST! TES TEST! TEST! TEST! TEST! TES TEST! Please, help?


Use AppendFile() instead of RewriteFile()

Andrmolja

2015-04-08 13:04:37

Yes it's ok. Thank you very much. Thanks KeepBotting and yourule97.

drag2270

2015-04-27 19:52:29

For my declare players i think i set everything correctly but it wont log in

heres the code i used:

program DeclarePlayers;

{$DEFINE SMART}
{$i srl-6/srl.simba}

procedure DeclarePlayers;
begin
HowManyPlayers := 1;
NumberOfPlayers(HowManyPlayers);
CurrentPlayer := 0;

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;
Players[0].Pin := '';
end;

begin
ClearDebug;
SetupSRL;
DeclarePlayers;
LoginPlayer;
end.

Can any1 help me find my mistake? For some reason it won't login

akela

2015-06-20 15:57:46

Is this guide outdated?
EDIT: im gonna be studying programming next year, and i can't wait x.D

jason5424

2019-06-10 15:55:57

Amazing still useful to this day