Jump to content

dynamic task selection


Jachos

Recommended Posts

Hey guys!

 

Newbie here. I'm writing my first chopper script using a standard node/task based framework, and I want to introduce a way to dynamically select a task (position, target, endconditions) when my script starts.

 

More specifically, I'm looking for some code magic that will run once on start, hold a few pieces of data, and be referable from within any of my node classes. Unfortunately I'm new to programming, so I'm clueless as to where I would even start searching for such a thing.

 

I attempted coding a task object which held static variables and was instantiated in my main script class, but I ran into goofy runtime errors that have me thinking there's a better way to accomplish my goal.

 

 

 

Link to comment
Share on other sites

 

I attempted coding a task object which held static variables and was instantiated in my main script class, but I ran into goofy runtime errors that have me thinking there's a better way to accomplish my goal.

 

Not sure if I fully understand you or not, but I am assuming you are trying to make an AIO chopper, where the user can select different locations etc.

 

This is a very simple example, which you can build upon.

 

You start by having an enum for each Tree, which contains an Area in which the trees can be found:

public enum Tree {

    NORMAL (new Area(0, 0, 0, 0)),
    OAK (new Area(0, 0, 0, 0));

    Area area;

    Tree(final Area area){
        this.area = area;
    }

    @Override
    public String toString(){
        char[] name = name().toLowerCase().toCharArray();
        name[0] = Character.toUpperCase(name[0]);
        return new String(name);
    }
}

Then when the script starts, have the user select what tree they want to chop:

import org.osbot.rs07.script.Script;

import javax.swing.*;

public class Woodchopper extends Script {

    @Override
    public void onStart() {

        Tree selectedTree = (Tree) JOptionPane.showInputDialog(null,
                "Select a Tree",
                "Woodchopper",
                JOptionPane.INFORMATION_MESSAGE,
                null,
                Tree.values(),
                Tree.values()[0]
        );
    }

    @Override
    public int onLoop() throws InterruptedException {
        return 0;
    }
}

Your Chop Node can then take the selected tree as a constructor parameter:

import org.osbot.rs07.script.Script;

public class ChopNode extends Node {

    private final Tree tree;

    public ChopNode(final Script S, final Tree tree) {
        super(S);
        this.tree = tree;
    }

    @Override
    public boolean validate() {
        return !S.getInventory().isFull();
    }

    @Override
    public void execute() {
        if(!tree.area.contains(S.myPosition())){
            S.getWalking().webWalk(tree.area);
        } else{
            chop();
        }
    }

    private void chop(){
        // chop the trees
    }
}

So now in your onStart, when you create the nodes, you can pass the selected Tree:

import org.osbot.rs07.script.Script;

import javax.swing.*;

public class Woodchopper extends Script {

    @Override
    public void onStart() {

        Tree selectedTree = (Tree) JOptionPane.showInputDialog(null,
                "Select a Tree",
                "Woodchopper",
                JOptionPane.INFORMATION_MESSAGE,
                null,
                Tree.values(),
                Tree.values()[0]
        );

        Node chopNode = new ChopNode(this, selectedTree);
    }

    @Override
    public int onLoop() throws InterruptedException {
        return 0;
    }
}

Hope that helps

  • Like 1
Link to comment
Share on other sites

Hope that helps

 

Perfect! Your example was well structured and easy to understand, and is equivalent to what I'm attempting to accomplish. Thanks homie! 

 

Sorry for my garbled example tongue.png it seems you understood. You guessed correctly about the AIO; this is a nicely generalizable construction, so I'm thinking things will work out nicely smile.png

 

 

Edited by Jachos
Link to comment
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.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...