Rsbot Scripting: Tutorial Three – Script Backbone
Learn how to build your script’s foundation using the magic of Enums and Switch statements!
BTOdell’s Tutorial Index
- <<Getting Started<<
- <Starting your Script< (Previous)
- *Script Backbone*
- >Fill In The Blanks> (Next)
- >>Making Your Script User Friendly>>
We left off last time after we discussed what the Script Manifest does and we implemented it into our script.
The next thing to build is the backbone of your script. We do this by first brainstorming simple phrases describing the process of mining.
For example: “WALKTOMINE”, “MINE”, “WAIT”, “WALKTOBANK”, “BANK”
These are simple phrases that describe the process of mining. These phrases can be stored as enums; I will go into more detail on what these are exactly but first let’s write the code and get it out of the way…
(Don’t worry that the “Actions” is underlined in yellow, it just means that it hasn’t been used yet.)
Quick-reference – ‘private’, what does it mean in Java? This is a modifier that causes outside sources from accessing this variable. This is good practice; so get used to making things private. (Somethings cannot be private)
Now we need to code an Action getter, which will find and return the next Action that your player needs to do.
- Create some variables at the top of your script: (Just below the start of the class)
- Add in the Action getter:
Really look over this code and try to understand what it does
Now that we have a good working Action getter, we can use this with a switch statement to have your player do only what it needs to do. Consider the following code:
This script still won’t work because we haven’t set some variables.