Drokle Posted October 1, 2017 Share Posted October 1, 2017 Hello botters, I made the following script just for practice. It is intended to withdraw bones of any kind from the bank and bury them. import org.osbot.rs07.api.model.Item; import org.osbot.rs07.api.model.RS2Object; import org.osbot.rs07.script.Script; import org.osbot.rs07.script.ScriptManifest; import java.awt.*; @ScriptManifest(author = "Drokle", info = "Babby's first script", name = "DrokleBone", version = 0, logo = "") public class DrokleBone extends Script { @Override public void onStart(){ log("This is it, you're running DrokleBone!"); } private enum State { BANK, BONE } @Override public int onLoop() throws InterruptedException { Item[] pockets = inventory.getItems(); for(Item thing: pockets) { if(thing.hasAction("Bury")) thing.interact("Bury"); sleep(random(500,550)); } RS2Object booth = getObjects().closest("Bank booth"); bank.open(); Item[] vault = bank.getItems(); for(Item thing: vault) { if(thing.nameContains("Bones")||thing.nameContains("bones")) thing.interact("Withdraw-All"); if(inventory.getEmptySlotCount() == 0) break; sleep(random(500,700)); } return random(400,800); } @Override public void onExit() { log("This is has been DrokleBone, hope you had a good one."); } @Override public void onPaint(Graphics2D g) { g.drawString("THIS IS IT, YOU'RE RUNNING DROKLEBONE!! GOOD JOB!!!!", 50,50); } } For some reason, when I run it, the VM eventually becomes unresponsive and I can't shut it down. Could anyone help me figure out why? It happens if I use it to bury bones far away from any bank. Best, Drokle Quote Link to comment Share on other sites More sharing options...
TheWind Posted October 1, 2017 Share Posted October 1, 2017 (edited) First of all, the reason that it is crashing is that the variable "booth" which represents a Bank booth is null if there is no bank booth loaded in the game near you, so when you call bank.open() it will throw a nullpointerexception. Second, you never used your states that you set up in the enum, so on every loop, it buries all bones you have in your inventory and opens the bank to withdraw more. I suggest you follow one of the guides to learn the flow that should be followed. Generally, only one action should be performed per loop of the onloop method. Meaning that each iteration only one interaction should occur in the game that takes place over the course of a tick. In your script, you are doing many. Hope that helps Edited October 1, 2017 by TheWind 1 Quote Link to comment Share on other sites More sharing options...
Drokle Posted October 1, 2017 Author Share Posted October 1, 2017 Thanks, I'll see if I can fix it Quote Link to comment Share on other sites More sharing options...
Apaec Posted October 1, 2017 Share Posted October 1, 2017 (edited) Hey ! Good effort! As @TheWind said, the key is to have one and only one 'action' line execute in one onLoop iteration. The reason for this is that you are programming for a live game and as such issues such as latency fluctuations can result in interactions failing. If you're relying on an interaction to succeed for future lines of code, this can cause horrible errors! A classic example is banking. For example calling: getBank().open(); getBank().withdraw("Example", 500); Is a big error - ask yourself, what if the first line fails? The the script will try to withdraw stuff from the bank but it's not open - uh oh! Instead, you want to make it only do what it needs to based on the current situation: if (getBank().isOpen()) { if (getBank().contains("Example") && getBank().getAmount("Example") >= 500) { getBank().withdraw("Example", 500); //Conditional sleep here } else { log("Not enough Example in bank"); stop(); } } else { getBank().open(); } -Apa Edited October 1, 2017 by Apaec Quote Link to comment Share on other sites More sharing options...
Drokle Posted October 3, 2017 Author Share Posted October 3, 2017 Thanks! Oh wow, that explains a lot. So does OSbot hang if an invalid command is being used? Quote Link to comment Share on other sites More sharing options...