SRL Archive - OSR Beginner Scripting Tutorials

Making your first script - Step by step


Marc000z

2012-10-07 12:19:59

I put a lot of effort into making this guide, so feedback and comments are more than welcome.
_____

I remember when I first started to learn about scripting with simba, and the amount of effort I put in looking through guides and already made scripts to finally learn the basics. However, I don't want that for others, so I'm making this EXTREMELY basic guide to get you started on script making.

What we'll be covering:

I. New Program
II. Mouse movements
III. Finishing the program


So without further ado, let's begin.

I. - New Program

Every time you open up Simba, and add a new tab (If it's not already open), it usually starts up with 3 basic lines:

program new;
begin
end.


What these lines mean:

"program new;" = This will be the name of the script you're making. So if I were to make a AIO Agility script, I could maybe name it, I could maybe make my text like this: "program AIOAgility;".

"begin" = This will be used for when we have our procedures finished, I'll talk more about them in the next chapter.

"end." = This also will be used for when we're done with our procedures.

II. - Mouse movements

This is the most basic and, in my opinion, one of the most fundamental parts of scripting. Instead of trying to explain how you'd make mouse movements, I'll just show you a VERY simple piece of code using mouse movents:

Regular code:

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

procedure Findinventory;
begin
Movemouse(643, 183);
Wait(200);
Clickmouse(643, 183, mouse_Left);
Wait(200);
end;

begin
Findinventory;
end.


Code with explanation:

program InventoryFinder; //Since this script's function will be soley to find the Inventory, I've named it "Inventory Finder".
{$i srl/srl.simba} //You should ALWAYS add this piece of code after "program new;". I won't go into detail, but in summary, this code allows you to do certain things.

procedure Findinventory; //This is our first procedure. Just like the name states (procedure), this is something we want our script to do. I named it Findinventory, because that's what it's going to do.
begin //After every procedure, we must state for it to begin.
Movemouse(643, 183); //This is our first mouse movement. We're going to make it more to these coordinates: 643, 183.
Wait(200); //It's not necessary to add a wait time, but it's advised. Here I added a 0.2 second wait time, but if I wanted to add 1 second, I'd put in Wait(1000);.
Clickmouse(643, 183, mouse_Left); //This is the coordinates we want our mouse to click, and what type of click (Left/Right click). Here I made it do a left click.
Wait(200); //Another wait time.
end; //Finally, the end of our procedure. Don't forget that to end a procedure, you have to add a semi-colen (;), instead of a fullstop (.).

begin//This is the section in which we state which procedures the script should do, and in what order.
Findinventory; //Since I only have 1 procedure, I only made it do "Findinventory"
end. //This is the final line of our script, don't forget you have to finish it off with a fullstop (.), instead of a semi-colen (; ).


III. - Finish the program

Now that we're done with the coding part, all that's left to do is find the client screen we want our script to work on, and run that bad boy!

To find the screen, all we need to do is: (Note: You can do this before you start making the script, too)


Now all that's left to do is click "Run".


_____

Have a question? Feel free to ask me anything.

Footy

2012-10-07 12:24:06

A few things to fix:

Remind readers never to use clickmouse or movemouse in runescape, instead, use clickmouse2 or mmouse. They are the more humanlike versions of the aforementioned. Also, you should explain what procedures are a little more in depth. If I had never coded before, that little snippet you gave wouldn't teach me what a procedure is very well. Its great to see newcomers posting stuff like this. Keep it up!

~Footy

ProJoe

2013-01-02 12:02:14

Awesome. This helps out a lot. I think i understand the basic layout of a script now. It might not sound like much but it really is.

Matsetst

2013-01-06 12:29:02

Maybe a newb question but when you have found your coordinates thanks to Simba which shows it @ left cornor of the program screen is there a shortkey to copy the coordinations or do you need to memorize it and then fill it in?

Great beginning of a guide !

Im btw trying to make a 'simple' woodcutting script for a RSPS which can cut willows and bank them at draynor. Simple mouse movements are fine with me atm… if it does the job im happy :)

Ian

2013-01-06 12:35:47

You can use the color picker tool to get your coordinates , just select the client, then select the color picker from the toolbar. Then move the colorpicker to where you want the coordinates, then click. It will print your coordinates to the debug box, as well as in the color picker window.