SRL Archive - Outdated Tutorials

Jim's Beginner Tutorial...[TUT]


jimthesoundman

2010-02-11 17:55:19

Here is my thoughts on writing your first script.

1. First, make sure you have SCAR & SRL & TortoiseSVN set up properly, there are a bunch of other tutorials in this category that tell you how to do that, so I won't repeat them here.

2. Remember that writing a good script is 99% planning, and 1% execution. Get out a pad of paper and a pen. Write out what sort of script you want to write, a sort of "mission statement" if you will. For example: "I want to write a script that chops willow logs in Draynor Village and banks them".

3. Log onto Runescape and perform the task you seek to replicate. Write down each step you are doing. This will be your framework for writing your script. For example, if we are writing a wood cutting program we would have a script that looks something like this:
Start at bank,
Open bank
If there is a pin number, enter that.
Deposit everything except axe.
Close bank.
Walk to tree.
Chop tree
Check if inventory full.
If not full, then repeat chop tree.
If full, then walk to bank.
Repeat script from beginning until required number of logs banked.

4. So now that you have your rough draft of what you want to do, next is to get some facts and figures. Open up SCAR, use the crosshairs to assign it to your RS window, and then drag the SCAR window off the edge of the screen so all you can see is the bottom left corner of the SCAR window. You will see the mouse coordinates there. Notice how they change when you drag your mouse around the RS window.

5. Now we will go through your script which we wrote in step 3 and write down the coordinates of different things we do. For instance if we need to click on a certain spot on the screen or the inventory window or tabs, we can write down the coordinates. Obviously a lot of these simple tasks are already built into SRL, so if we want to close the bank window, instead of telling the mouse to click at (490,35) we can just use the function CloseBank which is already built into SRL. BUT, and this is important, you usually want to have a backup plan or "failsafe" in case that CloseBank function doesn't work for some reason. So in this case these coordinates will usually be important.

6. Now that you have a good idea of WHERE you need to click, we need to figure out WHEN you need to click. Get a watch or use an online stopwatch like the one at http://www.online-stopwatch.com/ and run through your script again. Write down how long it takes you to perform each step of your script. Write down the total time it takes for one complete loop of all the steps. You want your script to run at approximately the same speed a human runs at. Scripts that run at super bionic speed usually get you banned pretty quick.
Remember, you want this script to look EXACTLY like it would if a human were playing. That means it can't be perfect, and it can't be too fast, and it can't do things exactly the same way every time. THIS CONCEPT IS THE MOST IMPORTANT THING YOU CAN LEARN AND SHOULD NEVER BE OVERLOOKED.

7. Now that we have our rough draft with times written down, time to start writing the actual script. Now, a key point most people don't grasp at the beginning is you don't want to write the entire script at once. You want to do it in tiny steps. Baby steps, if you will. Lets look again at our rough draft. Step one is Start at Bank.
So write a script that checks if you are at the bank, if it can tell you are at the bank, then it does "writeln('yes, I am at the bank');" and then quits. That's all. Just that one little bit of code. Check if you are at the bank and then say yes or no. So if you accomplish that, you then start working on step two, which is open the bank window. Write a few more lines of code to add on to what you already have. So now your script should check if you are at the bank and if you are, then open the bank window, then stop.
The way you stop the script is using the TerminateScript command.

8. That's all there is to scripting. Just keep adding small chunks of code, and test them out until you are happy they are working correctly, then add a few more lines of code. Remember that when you are building scripts, the WriteLN function is your best friend. It will tell you what is going on in your script, you can get it to tell you when a certain procedure or function has executed. You can have it tell you what the value of variables or strings are. Once you have a script running the way you want, check the total time to make sure it is running about the same speed as you did when you timed it in the very beginning.

9. If you get stuck, first step is to do a sarch on this forum and see if anyone has had a similar problem and how they solved it. Next you should see if there are any scripts posted that perform the same or similar task you are working on. Even if they are very old and broken scripts, you can still sometimes get some good ideas on how to work around a certain problem you are having. If neither of those solutions work, then post your problem in "Scripting Help" and someone will usually give you a great suggestion quickly.

10. Remember, scripting doesn't have to be complicated.
Read the section of this forum about "Standards". Standards are, as the name would indicate, a standard way of writing scripts so they don't get completely confusing. It is very easy to master and will save you a lot of hair-pulling later. Use lots of comments, comments are notes you write to yourself in your scripts so you can remember what the heck that line does when you come back to look at it in a couple months.

11. Work on simple scripts first, even if they still require some manual assistance from you to keep going, they still are making your RuneScape life easier. So don't feel like you have to be an mega expert and have everything perfect before you use your first script. Keep improving your scripts, and before you know it you will be a SRL Member.