sudoinit6 Posted December 4, 2016 Share Posted December 4, 2016 (edited) As the topic says this is my first java script. I have been studying JAVA for a couple weeks and think I am starting to get it. That being said I know there are some really stupid things in my script and my intent is to post it here and you guys and gals can tell me how bad it is and how to improve as a programmer. Saying I "wrote" this is fairly generous as I mostly looked at what other people did and made it work for what I wanted to do. I decided not to make a fisher or woodcutter because then I would just be copying some of the fine examples provided by this website, so in order to make sure I was learning not copying here is what this script does: Goes to "Drogo dwarf", tries to buy Iron ore, if there isn't enough to fill inventory hop to a different world and when full go bank. A couple of things that I know are done wrong: The loop to buy the ore. I tried to get it to buy 27 but the docs indicate it wants it in forms of 1,5,or 10. I would think there would be a way to tell it to buy exactly 27, but I can't figure it out. The other thing I am not happy with is the world hopper. Instead of going to a random f2p world I would rather keep them all in an array and tell it get the current world and then hop to the next, but that is beyond me as well. This script doesn't make much money, it wasn't the intent, this was to learn. I will say I am having a blast learning and scripting, hopefully I can make some more complicated ones soon. So here it is, let me know if I am on the right track and what I need to work on please! (Oh, and I didn't steal this from someone named jubjub, that's another online nick I use!) edit: Wow those code tags dont format well! Check the spoiler for my script. package jubjubOreRunner;import org.osbot.rs07.api.map.Area;import org.osbot.rs07.api.model.RS2Object;import org.osbot.rs07.script.Script;import org.osbot.rs07.script.ScriptManifest;@ScriptManifest(name = "Ore Buyer", author = "jubjub", version = 1, info = "Buys Iron Ore", logo = "")public class jubjubOreRunner extends Script {private State state;Area Shop = new Area(3033, 9847, 3038, 9844);Area TheBank = new Area (3092, 3494, 3094, 3490);public int storeAmount;private enum State{BuyOre,WalkToOre,Bank,WalkToBank}private State getState(){if (getInventory().isFull() && TheBank.contains(myPlayer())){return state.Bank;}if (getInventory().isFull() && !TheBank.contains(myPlayer())){return state.WalkToBank;}if (!getInventory().isFull() && Shop.contains(myPlayer())){return state.BuyOre;}if (!getInventory().isFull() && !Shop.contains(myPlayer())){return state.WalkToOre;}return state.WalkToOre;}public void onStart() {}@@Overridepublic int onLoop() throws InterruptedException {state = getState();switch (state) {case Bank:if (!getBank().isOpen()) {getBank().open();} else {getBank().depositAllExcept("Coins");}case WalkToBank:getWalking().webWalk(TheBank);break;case BuyOre:npcs.closest("Drogo dwarf").interact("Talk-to");Script.sleep(Script.random(1000, 5000));dialogues.clickContinue();Script.sleep(Script.random(1000, 2000));dialogues.completeDialogue("Do you want to trade?");Script.sleep(Script.random(1000, 2000));storeAmount = store.getAmount(440);int counter = 3;while (counter > 0){store.buy(440,10);Script.sleep(Script.random(500, 1500));counter = counter -1;}store.close();if (storeAmount <= 27){worlds.hopToF2PWorld();Script.sleep(Script.random(4000, 5500));}break;case WalkToOre:getWalking().webWalk(Shop);break;}return random(150,175);}} Edited December 4, 2016 by sudoinit6 Quote Link to comment Share on other sites More sharing options...
Precise Posted December 4, 2016 Share Posted December 4, 2016 (edited) I'd look into nested if statements like so: private State getState(){ if (getInventory().isFull()) { if(TheBank.contains(myPlayer())){ return State.Bank; } else { return State.WalkToBank; } } else if(Shop.contains(myPlayer())) { return State.BuyOre; } return State.WalkToOre; } Also would look into naming conventions. Edited December 4, 2016 by Precise 1 Quote Link to comment Share on other sites More sharing options...
Team Cape Posted December 4, 2016 Share Posted December 4, 2016 http://osbot.org/forum/topic/111298-basic-java-naming-conventions-simple-mini-tut/ I made this in a few minutes after seeing what you posted. Quote Link to comment Share on other sites More sharing options...
sudoinit6 Posted December 4, 2016 Author Share Posted December 4, 2016 http://osbot.org/forum/topic/111298-basic-java-naming-conventions-simple-mini-tut/ I made this in a few minutes after seeing what you posted. My apologies, I will try to learn and adhere to naming conventions. Thanks for this guide! 1 Quote Link to comment Share on other sites More sharing options...