Jump to content
Frequently Asked Questions
  • Are you not able to open the client? Try following our getting started guide
  • Still not working? Try downloading and running JarFix
  • Help! My bot doesn't do anything! Enable fresh start in client settings and restart the client
  • How to purchase with PayPal/OSRS/Crypto gold? You can purchase vouchers from other users
  • Curious question about java class files


    PancakePunche

    Recommended Posts

    Posted

    Hello! I have been following several guides in the tutorials sections to get an idea on how to code dreambot bots. I have learned quite a decent amount and have some small java background.

    My question for you guys is that I understand how a class file functions and that it runs from top to bottom etc. but my issue is that I need to know how to execute other class files from within another class file. The bot I plan to make has to be able to identify certain items in the game upon receiving them then run a very specific string of conditions and actions. Because of this I want to have separate scripts/class files that the bot will switch to when the condition is met.

     

    So If "item id" is in inventory, run class "class name"

     

    If this could be explained to me it would be much appreciated.

     

    Thanks!

    Posted

    Hello! I have been following several guides in the tutorials sections to get an idea on how to code dreambot bots. I have learned quite a decent amount and have some small java background.

    My question for you guys is that I understand how a class file functions and that it runs from top to bottom etc. but my issue is that I need to know how to execute other class files from within another class file. The bot I plan to make has to be able to identify certain items in the game upon receiving them then run a very specific string of conditions and actions. Because of this I want to have separate scripts/class files that the bot will switch to when the condition is met.

     

    So If "item id" is in inventory, run class "class name"

     

    If this could be explained to me it would be much appreciated.

     

    Thanks!

    You can either multi-thread or use a Node-system. Or you can inherit your class into the class you want it to be in to.

     

    Otherwise, i would suggest creating class methods, so in your onLoop():

     

    if(getInventory().contains(itemID)){

       executeMethod();

    }

     

     

    Outside your onLoop(), but inside your class:

     

    public void executeMethod(){

    //CODE FOR THE STUFF YOU WANT IT TO DO AFTER IT SEES YOU HAVE THE ID IN THE INVENTORY

    }

     

     

    note: the executeMethod() will act the same as another class file, it will call the method and reads from the top to the bottom of the method and then continue your onLoop().

    Posted

    Hello! I have been following several guides in the tutorials sections to get an idea on how to code dreambot bots. I have learned quite a decent amount and have some small java background.

    My question for you guys is that I understand how a class file functions and that it runs from top to bottom etc. but my issue is that I need to know how to execute other class files from within another class file. The bot I plan to make has to be able to identify certain items in the game upon receiving them then run a very specific string of conditions and actions. Because of this I want to have separate scripts/class files that the bot will switch to when the condition is met.

     

    So If "item id" is in inventory, run class "class name"

     

    If this could be explained to me it would be much appreciated.

     

    Thanks!

    A class itself doesn't necessarily run from top to bottom. Each method in a class will run from top to bottom but those methods will run in the order they are called.

    Posted

    A class itself doesn't necessarily run from top to bottom. Each method in a class will run from top to bottom but those methods will run in the order they are called.

    + this, forgot to mention :P

    Posted

    You can either multi-thread or use a Node-system. Or you can inherit your class into the class you want it to be in to.

     

    Otherwise, i would suggest creating class methods, so in your onLoop():

     

    if(getInventory().contains(itemID)){

       executeMethod();

    }

     

     

    Outside your onLoop(), but inside your class:

     

    public void executeMethod(){

    //CODE FOR THE STUFF YOU WANT IT TO DO AFTER IT SEES YOU HAVE THE ID IN THE INVENTORY

    }

     

     

    note: the executeMethod() will act the same as another class file, it will call the method and reads from the top to the bottom of the method and then continue your onLoop().

    So, can I put:

     

    public void executeMethod(){

    }

     

    Inside a different class and when the conditions are met will it run? Or does this have to exist inside the main class outside of the loop? My issue is... the amount of if conditions being met I feel would be a lot to cram into a single class file. In order to keep it organization I would like to separate it all.

     

    If I make a class file that has an onLoop(): with

     

    if(getInventory().contains(itemID)){

       executeMethod();

    }

     
    inside of it. Constantly checking every so many miliseconds the issue here is that I would have so many class files constantly running which would be process intensive. It isn't possible to execute a class file from an if boolean?
     
    If you must know I am looking to design a bot that solves clues. This means that out of all the clue scrolls (easy) the bot must be able to know which one it has then execute the series of events to solve it. Which is why you would understand that cramming all of that into one class would be incredibly bad and just designing a class file that solves the clue it has based in a
     

    if(getInventory().contains(clueID)){

    }

     

    Then move to the class coded for that specific clue would be more beneficial, but having 15+ class files are updating at once would be way too intense.

     
    Posted

    Well aside of your intentions of the script:

     

    You can always call a method from another class in your main onLoop() method. To do so you need to inherit the class with the method in it into your main class

    public class MethodClass {
    
    public void executeMethod(){
    //the code
    }
    }
    
    
    
    //Then in your main class:
    
    public class mainClass extends AbstractScript{
    MethodClass inheritClass = new MethodClass();
    
    public int onLoop(){
       if(getInventory().contains(ITEMID){
          inheritClass.executeMethod();
          }
       }
    }
    
    
    

    Not sure if you need to set MethodContext as the parameter of executeMethod for this.

     

    For a clue solver, I would use a switch-case statement to determine which step you need to do.

     

     

    However, I strongly advice against making a clue solver if you know this little of Java (not to be rude). It's not as easy as it looks like!

    Posted

    I would suggest learning more of the core Java principles before starting to script. It'll help a ton in the long run.

    Archived

    This topic is now archived and is closed to further replies.

    ×
    ×
    • Create New...

    Important Information

    We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.