Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
Buy OSRS Gold

Einstein

Einstein's Scripting Tutorial - Part 1

Recommended Posts

Einstein's Scripting Tutorial

Part 1 - The Basics

 

This tutorial was written specifically for the users that are interested in learning how to code their own scripts, but lack any kind of technical knowledge. After reading this tutorial, you will understand the basics and have a good starting point in this journey.

 

There are plenty of concepts that you will need to learn and understand, but you shouldn't get discouraged by the complexity, as everything will get easier with time, if you put in enough effort.

Let's get started!

 

 

 

 

What exactly is a script?

According to Wikipedia, scripts are:

"programs written for a special run-time environment that automate the execution of tasks that could alternatively be executed one-by-one by a human operator".

 

latest?cb=20141201090409       Sounds familiar?

 

In our case, the special run-time environment is the TRiBot client.

Scripts written for TRiBot will only work within it. You cannot run a script by double clicking the files on your desktop. You need to start a TRiBot instance, offer it a script, and then the client will execute it line by line.

 

A script is basically just a set of instructions:

  • go to the bank
  • kill a goblin
  • move the camera
  • chop down a tree

 

 You can add rules and conditions to determine if and when to execute the instructions:

  • if the inventory is full: go to the bank
  • if my player is not in combat: click the next goblin
  • while the player is busy cutting the tree: idle - do nothing
  • if the player reached level 40 fishing, switch from trout/salmon to lobsters

 

 

 

 

 

The Beginner Pitfall

So far so good, everything is clear: just some basic instructions for your bots.

The problem is that TRiBot won't be able to execute anything written in plain English. We write scripts in a programming language called Java.

After writing the Java source code, we use a program called a "compiler" to convert the source code into executable "bytecode", and we end up with a working script that can be executed by the client.

 

If you don't have any programming experience, a lot of things (probably everything) will seem utterly incomprehensible at first.

Don't get discouraged or frustrated if you don't understand it from the first attempt. Everyone without exception, even the most brilliant of programmers, have started at the same point in which you are today: absolute beginner.

By deliberate practice, you will gradually become better at it.

 

 

 

Real Life Script

Here is a real-life script that you probably ran today, without even realizing it:

The comments (green) are not executed, they just explain the code, I included them just to make matters more clear. ("!" - means "NOT" )

DT3QOVH.png

 

 

 

 

 

TRiBot Script

 

Setting up a new script:

1. Download any Java IDE if you haven't already. An IDE is a code editor that will make scripting easier. You can find a free IDE by searching online. In this tutorial, we will be using Eclipse.

2. Create new project, this will be your script. You can name it as you wish.

3. Go to Java Built Path (depends on IDE) >  add external JAR > navigate to .tribot\dependancies > add "TRiBot.jar"

4. Create a new package called scripts (lowercase 's'). It's very important to name the package as such.

5. Create a new class, this can also be named as you wish (by convention it starts with uppercase).

PTebJtc.png     If your setup looks like this, then you are ready to move on.

 

 

The actual coding:

The first step is to extend the class 'Script':

    aDvfL4w.png     

 

This will generate two different errors.

1. You need to import the abstract class Script. Just use the IDE's auto import shortcut (Eclipse: Ctrl + Shift + O).

2. You need to implement the method run from the Script class. Either click the error warning and select "Add unimplemented methods", or write the code yourself as it's shown below (run method):

S2x81Ps.png

 

The run method will be called automatically when you press M7qNtMw.png in the TRiBot client.

The instructions contained within the run() method will be executed in sequence, from top to bottom (Blue Arrow). If all the instructions are executed, the script will stop. In order to prevent this from happening, we will write all the instructions inside an infinite loop:

When control flow reaches the end of the loop, instead of exiting the method, it will return back to the top, executing the instructions again (Red Arrow).

 

VDBMUrj.png

 

 

Running the script

Your IDE will automatically compile the .java files into .class files.

Navigate to your workspace (the location of your project) and copy the .class files. Paste them in C:\Users\UserName\AppData\Roaming\.tribot\bin\scripts.

If you packaged the script correctly, it will appear in the script list when you press M7qNtMw.png.

VIP is required to run local scripts.

 

 

 

 

 

Code example

 

Here is a very simple script that first checks whether or not the inventory is full, and decides what to do next based on this information.

If the inventory is full, the script will walk to the nearest bank and deposit everything. Otherwise if the inventory is not full, the script will walk to the potato field and will pick potatoes continuously until the inventory will be full:

 

Xfw2ryP.png

 

 

Null Pointer Exception / Array Index Out of Bounds Exception

 

Two of the most common bugs that new scripters encounter are the Null Pointer Exception and the Array Index Out of Bounds Exception.

It's very easy to avoid them if you understand them correctly. They both refer to the same idea:

You cannot perform actions upon something that doesn't exist.

 

 

Null Pointer Exception

usFOhvq.jpg     Consider the following table. Let's try to eat the apple that's on the table and see what happens.

// Declare a variable of type Apple, named 'apple'.
Apple apple; 

// Search the table for the nearest apple:
// Assign the variable 'apple' with the value returned by the method 'getNearestApple()' 
apple = table.getNearestApple(); 

// Attempt to eat the apple stored in the 'apple' variable
apple.eat();

Line 2: Since there is no apple on the table, the method getNearestApple(), will assign the value null (nothing) to the 'apple' variable.

Line 3: Since the variable apple points to nothing, attempting to perform an action upon it (eat the apple) will throw a Null Pointer Exception.

 

How to prevent a null pointer exception on line 3:

if (apple == null)
  print("The apple variable is null, let's leave it alone.");
else
  apple.eat();
  

 

 

 

Array Index Out of Bounds Exception

 

OXPQlq8.png

 

We have an array of 4 apples.

Let's try to eat the 5th apple and see what happens.

apples[4].eat();

Since the array only contains 4 elements (indexes 0 to 3), attempting to perform an action on the 5th element (index 4) will throw an Array Out of Bounds Exception.

How to prevent this from happening:

if (apples.length < 5)
  print("The array's length is less than 5. We are unable to access the 5th element. (index 4)");  
else
  apples[4].eat();

 

 

 

 

The end
 

I strongly advise you to learn Java before getting into scripting. Here are some useful links:

 

Here is the link for the TRiBot API, which is one of the most valuable scripting tools, so make sure to bookmark it: https://tribot.org/doc/

 

Thank you for reading my first scripting tutorial. I hope that you've learned something from it, and that you're one step closer to writing your own scripts.

And remember: you will only get better at this by deliberate practice. It's hard, but not impossible.

 

Edited by Einstein
  • Like 14
  • Thanks 3

Share this post


Link to post
Share on other sites
Guest

Thanks Einstein, this is definitely helpful for someone who hasn't dabbled in scripting before. Now to find time to put work into a decent script. Perhaps a great addition to this would be to give a basic example of a GUI and progress display? Assuming you want to pursue further tutorials.

Great work!

  • Like 2

Share this post


Link to post
Share on other sites
7 hours ago, aexious said:

Thanks Einstein, this is definitely helpful for someone who hasn't dabbled in scripting before. Now to find time to put work into a decent script. Perhaps a great addition to this would be to give a basic example of a GUI and progress display? Assuming you want to pursue further tutorials.

Great work!

Thanks, I'm glad you liked it.

I might write another tutorial on paint, GUI and other script features.

  • Like 1

Share this post


Link to post
Share on other sites
On 11/2/2017 at 1:27 AM, aexious said:

Thanks Einstein, this is definitely helpful for someone who hasn't dabbled in scripting before. Now to find time to put work into a decent script. Perhaps a great addition to this would be to give a basic example of a GUI and progress display? Assuming you want to pursue further tutorials.

Great work!

On 11/2/2017 at 8:53 AM, Einstein said:

I might write another tutorial on paint, GUI and other script features.

On 11/10/2017 at 5:13 AM, TristanWPA said:

This would also be great  ▲ ▲  ....  Thanks for the entertaining and easy to understand tutorial, well written! 

 

Done!

 

  • Like 1

Share this post


Link to post
Share on other sites
1 hour ago, ryansmith1998 said:

 

What do you mean by this? 

You can write a simple script fairly easily with no framework and just using a basic while loop, but begin create a massive script using just that and it'll become messy, so people often find a framework they prefer. (State, "Node/Task", creating other loops etc)

Share this post


Link to post
Share on other sites

All my tutorials have been updated, and will be updated again in the future as I improve my ability to explain things.

 

This is the last 'Updated' message, as from now on, any subsequent updates will be done without notification. You can see when the last update occurred, by reading the message in the bottom left corner of the threads:

pIV9i9Z.png

 

 

 

Share this post


Link to post
Share on other sites
Guest
8 minutes ago, Einstein said:

XZfGuCk.png

 

 

Undeniable proof that this this tutorial will make you write the @BestScripts in the world.

 

Sorry @BestScripts, I've just seen it. Welcome to the forums and good luck with your code. :D

 

Lol. Yeah i was just trying to find an entry point. Later when ill have time im going to write some scripts. Dont know if ill publish them yet tho

  • Like 1

Share this post


Link to post
Share on other sites

Maybe I'm just an idiot, but any time I try adding TriBot.jar as an external jar nothing's showing up. As a result I have no referenced libraries.   import org.tribot can also not be resolved. I've ran the tribot launcher multiple times to refresh this TriBot.jar file (currently TRiBot3.05.jar)

Edit: ignore me it's Thursday and jagex just pushed an update so the loader is behind and not updating my tribot version

Edited by 2Header

Share this post


Link to post
Share on other sites
8 hours ago, 2Header said:


Edit: ignore me it's Thursday and jagex just pushed an update so the loader is behind and not updating my tribot version

These can be deleted I've finally come to my senses and looked in the right folder 

Edited by 2Header
  • Haha 1

Share this post


Link to post
Share on other sites
Guest

this might be a dumb question, but is the Tribot.jar file that is attached in his Referenced Libraries the same Jar you download on the home page?

When I download the Jar on the homepage I get TriBot_loader.jar. If I use that as an external library I dont seem to be able to reference org.tribot.scripts.*.

 

image.thumb.png.8580e5a32aeb25144c9d967d0a3aa951.png

Share this post


Link to post
Share on other sites
1 hour ago, dudeinbanff said:

this might be a dumb question, but is the Tribot.jar file that is attached in his Referenced Libraries the same Jar you download on the home page?

When I download the Jar on the homepage I get TriBot_loader.jar. If I use that as an external library I dont seem to be able to reference org.tribot.scripts.*.

 

image.thumb.png.8580e5a32aeb25144c9d967d0a3aa951.png

No, its the tribot.jar in your .tribot/dependecies
If on windows it's ->C:\Users\"User_Name"\AppData\Roaming\.tribot\dependancies

You can use %appdata% in the start->search bar to open the Roaming folder .And navigate to the .tribot folder(dot->.tribot)

Edited by Red_Spark
  • Like 1

Share this post


Link to post
Share on other sites

I'd buy a 4000 page tribot scripting book if you made one Einstein. I can see it now

 

"Einsteins Scripting Bible" 4,000 pages, covering everything from Bot farming, to AI-powered antiban, to Implimenting a Human Mouse and reaction timing.

  • Like 1

Share this post


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.
Note: Your post will require moderator approval before it will be visible.

Guest
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.


  • Our picks

    • Gradle is a build tool used to accelerate developer productivity.

      We recently setup a Maven repository (TRiBot Central) to make it easier for scripters to create scripts. Check it out here: https://gitlab.com/trilez-software/tribot/tribot-central/-/packages

      Furthermore, we've released a simple Gradle project to make it easy to run TRiBot and develop scripts for it. Check it out here: https://gitlab.com/trilez-software/tribot/tribot-gradle-launcher

      The goals of TRiBot Central are to:

      Deliver updates to TRiBot faster


      Better organize TRiBot's dependencies (AKA dependancies)


      Make it easier to develop scripts for TRiBot


      Make it easier to use and run TRiBot


      Note: TRiBot won't be able to run scripts from within this project until TRiBot's next release.
      • 10 replies
    • Hi everyone,

      I'd like to thank everyone for their patience in this transition period. Since last week, we've worked out the remaining bugs with this integration.

      Some users have still been having issues with connecting their forums account to their Auth0 account. To resolve this, we've imported all forums accounts into Auth0.

      Unfortunately, the accounts which were imported today were using an unsupported password hashing algorithm. Hence, random passwords were set during the import.

      What does this mean for me?

      If you've previously linked your forums account to your Auth0 account, you don't have to do anything. Nothing changes for you.


      If you haven't logged in via our new login yet,

      Try logging in with your forums email address and the last password you used


      If you are unable to login, please use the "Forgot password" tool on the login page:
      Follow the instructions to reset your password
       
      • 17 replies
    • Hello everyone,

      Last week we tried to roll out Auth0 Login, but we lost that battle. Now it's time to win the war!

      Important changes

      When logging into the client, you'll now have to enter your Auth0 account credentials instead of your forums credentials

      Note: 2FA is still handled through your forums account (for the time being)



      Changes for existing users

      You'll have to link your Auth0 account to your forums account here: https://tribot.org/forums/settings/login/?service=11


      Auth0 accounts have been created for most existing users. Please use your forums email address and password to login.



      Important notes

      Make sure to verify your email address upon creating a new Auth0 account


      When we mention your Auth0 account, we mean your account used for auth.tribot.org as displayed below
      • 81 replies
    • To better support the upcoming changes (TRiBot X, new repository), we're switching our login handler to Auth0. Instead of logging in with the standard form, you'll now be required to login through our Auth0 application.

      All existing accounts which have been used within approximately the past year have been imported into Auth0 using the same email and password combination which has been stored on the forums.

      What does this mean for users?

      Your account credentials are now even more securely stored


      You'll be able to login via Facebook, Google, and others in the future


      Is there anything users have to do differently now?

      Existing users: You'll have to login with the standard login, open your Account Settings, then link your Auth0 account


      New users: You'll be redirected to our Auth0 app (auth.tribot.org) where you'll be able to create an account


      Why was this change made?

      The new apps we are creating (such as the new repository) aren't able to use the forums to handle user logins


      To centralize all user accounts in one area


      To ensure that the client login doesn't go down when the forums are having problems


      To speed up our development


      Other considerations

      There's no documentation or official support for using Invision Community combined with Auth0, so there are still a few kinks we're working out


      We're in the works of creating an account management panel specifically for Auth0 accounts (ETA August)


      It's not possible to change email addresses for the time being (this will be resolved this August)


      Changing passwords is a weird process for the time being. To change your password, you'll have to use the "Don't remember your password" tool on the Auth0 login page
      • 11 replies
    • Over the past month, we've been working hard on TRiBot's new repository - a much needed update. This change has been deemed necessary for TRiBot X, and will allow us to really speed up development of all aspects of TRiBot.

      Today we are going to share what we've been working on!


      Now you must be wondering what kind of features the new repository will have.... well, you'll have to be patient for a little while longer. We're still figuring out various technical aspects so we can't provide answers to all possible questions. We're also focusing on development rather than writing about it so that everyone can get access to our latest developments at lightning speed. I will however answer a few users' questions.

      We're planning on a release of this early to mid August, giving users some goodies before TRiBot X's release.

      Thank you all for being patient. I hope everyone is excited as much as I am!
      • 19 replies
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...