Jachos Posted March 27, 2016 Share Posted March 27, 2016 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. Quote Link to comment Share on other sites More sharing options...
Psvxe Posted March 27, 2016 Share Posted March 27, 2016 I did create a similar framework. I'm not quite sure if I understand you right however. Do you mean you want to add / pause / remove tasks / nodes on conditions from any other task you're running at the moment? If so, I can help you. Quote Link to comment Share on other sites More sharing options...
Explv Posted March 27, 2016 Share Posted March 27, 2016 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 1 Quote Link to comment Share on other sites More sharing options...
Jachos Posted March 27, 2016 Author Share Posted March 27, 2016 (edited) 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 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 Edited March 27, 2016 by Jachos Quote Link to comment Share on other sites More sharing options...