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

  1. <<Getting Started<<
  2. <Starting your Script(Previous)
  3. *Script Backbone*
  4. >Fill In The Blanks(Next)
  5. >>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.

  1. Create some variables at the top of your script: (Just below the start of the class)
  2. 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.

See Also: 

Easily Double Your Triond/Blog/Article Page Views 

3
Liked it
1 Comment
  1. Posted July 8, 2010 at 11:08 am

    Nice share..

Leave a Reply
comments powered by Disqus