Jump to content

A Beginner's Guide

Recommended Posts

Script Writing Guide & FAQ:
By: ProjectPact
Work in Progress
What is a Method Number?
When you add a new Check or Action to the script, you may notice something that says ‘[x]:’ (where ‘x’ could be any number) at the beginning of the description. The number inside the brackets refers to the ‘Method Number’. The Method Number is unique because it connects Checks (anything that contains ‘->’ in the description) to an Action (anything that does NOT contain ‘->’ in the description). You may combine multiple Checks to a single Method Number. Checks control the function of the Action(s). If any of the Checks fail for a specific Method Number, the Action(s) for that Method Number will not be performed. You may put multiple Actions within a single Method Number, however the script will loop through ALL Checks prior to running any Actions, so you may not do something like: Check, Check, Action, Check, Action in a single Method Number, because it would actually read as: Check, Check, Check, Action, Action. A simple example may be seen below on the proper way to setup a script with Checks and Actions.
[0]: -> If inventory is not full
[0] -> If RS20bject exists - [Tree]
[0]: Interact With RS2Object - [Tree, Chop down]
In the example there are two checks present, and a single action. Notice all three lines contain ‘[0]’, which states that the Method number for the following example is 0. The script makes sure that the inventory is not full, and that the RS2Object (a Tree in this case) exists before trying to interact with it. The script should automatically make the next line following the Action a new Method Number, 1.

How may I edit a script with Method Numbers?
When editing a script, make sure you are setting the Method Number accordingly. The script will automatically try to guess the Method Number, but this is not always accurate. You may edit a line's Method Number by right clicking and selecting, "Edit Method Number [X]". All you need to do is remember that every Action needs its own unique Method Number. When adding a method, you don't have to worry about Method Numbers going in exact chronological order ([1], [2], [3]...etc) even though it is good practice to make them... but you still have to ensure that Method Numbers go in ascending order. If not, the script will not save properly. Remember, you may always add/edit/delete a line in case you need to.

How do I edit scripts?
To edit a script, make sure you select the “Rearrange” checkbox on the bottom left corner of the GUI. If you do not check this box, you will not be able to drag and drop Checks or Actions. If you right click anywhere on your code, you will see a menu appear that has a lot more options for you to use. Alternatively, you make access another option menu that contains different options by selecting “Script” on the top left corner of the GUI, then going to “Edit”.

How do you use OR statements?
OR statements are a type of check that allows you to check for multiple possibilities for an Action to run. It reduces the need to create multiple separate methods for Checks that would use the same Action. You may use multiple OR statements within a single Method Number. Below, you will find an example of how to properly use an OR statement.

How do you use ELSE statements?
ELSE statements are considered a type of Action that will run an alternate action if a Check fails. You should only use one ELSE statement per Method Number. Below, you will find an example of how to properly use an ELSE statement.

What is a Boolean variable?
A boolean is simply a true or false statement. They are very powerful in your scripts to keep up with information if you use them correctly. Using one can reduce the amount of checks required in your script, as well as make it easier to call in multiple methods.

How do #containsPartialText methods work?
The text you search for should either be at the beginning, or the end of an item. You may not search for something in the middle of an item's name.
Sort by:
When you search for an item, you may sort the item to either get the highest, or lowest value. In this example, lets say in my inventory I have a "Stamina potion(4)" and a  "Stamina potion(1)".
Sort by Highest: If I search for text containing "Stamina potion", and sort by "Highest", the bot will find "Stamina potion(4)".
Sort by Lowest: If I search for text containing "Stamina potion", and sort by "Lowest", the bot will find "Stamina potion(1)".
Text placement:
Depending on where you select the text placement, either "Starts with" or "Ends with", the script will find item(s) with the desired text.
Starts with: "Stamina potion" will find all "Stamina potion(4)", "Stamina potion(3)", "Stamina potion(2)", "Stamina potion(1)" 
Ends with:"ore" will find all "Copper ore", "Iron ore", "Gold ore"...etc

How do I debug issues with my script?
Script Factory has a built in debugging system that helps let you know what is failing so you can find issues much faster. On Script Factory, go to Script->Settings->Print to logger. What this will do is print lines to OSBot's debugger to display what is passing, or failing. Now, you need to open up OSBot's debugger to see the printed information. To do that, go to OSBot's client and hit Settings->Toggle logger. A new window should appear where you can see the printed information from Script Factory. If the logger is going too fast, you may always stop your script in Script Factory from running so you can look through the logs. 

REMEMBER: When you are not debugging a script, disable the 'Print to logger' option in Script Factory! This wastes a lot of resources and slows down script performance/load times.

Where are my local scripts saved?
"C:\User\OSBot\Data\ProjectPact\OSRS Script Factory\Local Scripts"
"User\OSBot\Data\ProjectPact\OSRS Script Factory\Local Scripts"

How do you run scripts via CLI?
Script ID's:
Standard OSRS Script Factory: 1097
Expansion OSRS Script Factory: 1144
New CLI args:
* after each arg, place a underscore "_"
-script 1097:name=script1_popups=false_editor=true_queue=false

If there is something in particular you would like to see added to the list, please let me know down below!
Edited by ProjectPact
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...