Lol_marcus Posted May 17, 2020 Share Posted May 17, 2020 So I did some quick reading, but I still don't quite understand what the lack of the "@Override" handler for the 2nd and 3rd onLoops will do to my script, if anything at all? I'm using a simple drop down menu for the options. I've run to all banks and it works fine. When I ask if it'll work in the long run is, if I have a script that loops. Like a WCing script. If I give it the option to cut willows, and the other oaks, will it keep running fine without the Override? package core; import javax.swing.JOptionPane; import org.osbot.rs07.api.map.constants.Banks; import org.osbot.rs07.script.Script; import org.osbot.rs07.script.ScriptManifest; @ScriptManifest(name = "Bank Walker", version = 1, author = "Marcus", logo = "", info = "Walks and runs to banks") public class Main extends Script { @Override public void onStart() throws InterruptedException { String userOptions[] = {"Varrock", "Falador", "Edgeville"}; String userChoice = ""+(String)JOptionPane.showInputDialog(null, "Choose a location", "Bank Walker", JOptionPane.PLAIN_MESSAGE, null, userOptions, userOptions[1]); if(userChoice.equals("Varrock")) { onLoop(); } else if (userChoice.equals("Falador")) { onLoop2(); } else if (userChoice.equals("Edgeville")) { onLoop3(); } else { stop(false); } } @Override public int onLoop() throws InterruptedException { if (Banks.GRAND_EXCHANGE.contains(myPosition())) { stop(false); } else { combat.toggleAutoRetaliate(false); getWalking().webWalk(Banks.GRAND_EXCHANGE); } return 700; } public int onLoop2() throws InterruptedException { if (Banks.FALADOR_WEST.contains(myPosition())) { stop(false); } else { combat.toggleAutoRetaliate(false); getWalking().webWalk(Banks.FALADOR_WEST); } return 700; } public int onLoop3() throws InterruptedException { if (Banks.EDGEVILLE.contains(myPosition())) { stop(false); } else { combat.toggleAutoRetaliate(false); getWalking().webWalk(Banks.EDGEVILLE); } return 700; } } Quote Link to comment Share on other sites More sharing options...
Gunman Posted May 17, 2020 Share Posted May 17, 2020 https://www.geeksforgeeks.org/overriding-in-java/ 1 Quote Link to comment Share on other sites More sharing options...
Camaro Posted May 17, 2020 Share Posted May 17, 2020 I think something like this is more what you're looking for package core; import javax.swing.JOptionPane; import org.osbot.rs07.api.map.constants.Banks; import org.osbot.rs07.script.Script; import org.osbot.rs07.script.ScriptManifest; @ScriptManifest(name = "Bank Walker", version = 1, author = "Marcus", logo = "", info = "Walks and runs to banks") public class Main extends Script { int task; @Override public void onStart() throws InterruptedException { String userOptions[] = {"Varrock", "Falador", "Edgeville"}; String userChoice = ""+(String)JOptionPane.showInputDialog(null, "Choose a location", "Bank Walker", JOptionPane.PLAIN_MESSAGE, null, userOptions, userOptions[1]); if(userChoice.equals("Varrock")) { task = 1; } else if (userChoice.equals("Falador")) { task = 2; } else if (userChoice.equals("Edgeville")) { task = 3; } else { stop(false); } } @Override public int onLoop() throws InterruptedException { switch (task) { case 1: return taskOne(); case 2: return taskTwo(); case 3: return taskThree(); } return 700; } public int taskOne() throws InterruptedException { if (Banks.GRAND_EXCHANGE.contains(myPosition())) { stop(false); } else { combat.toggleAutoRetaliate(false); getWalking().webWalk(Banks.GRAND_EXCHANGE); } return 700; } public int taskTwo() throws InterruptedException { if (Banks.FALADOR_WEST.contains(myPosition())) { stop(false); } else { combat.toggleAutoRetaliate(false); getWalking().webWalk(Banks.FALADOR_WEST); } return 700; } public int taskThree() throws InterruptedException { if (Banks.EDGEVILLE.contains(myPosition())) { stop(false); } else { combat.toggleAutoRetaliate(false); getWalking().webWalk(Banks.EDGEVILLE); } return 700; } } 1 Quote Link to comment Share on other sites More sharing options...
Lol_marcus Posted May 17, 2020 Author Share Posted May 17, 2020 5 minutes ago, Camaro said: I think something like this is more what you're looking for My guy! That makes so much more sense! Plus it opens up so many possibilities. Thank you! Quote Link to comment Share on other sites More sharing options...
TheMcPker Posted May 17, 2020 Share Posted May 17, 2020 (edited) Area bank; @Override public void onStart() throws InterruptedException { String userOptions[] = {"Varrock", "Falador", "Edgeville"}; String userChoice = ""+(String)JOptionPane.showInputDialog(null, "Choose a location", "Bank Walker", JOptionPane.PLAIN_MESSAGE, null, userOptions, userOptions[1]); switch(userChoice) { case "Varrock": bank = Banks.FALADOR_WEST; break; case "Falador": bank = Banks.FALADOR_WEST; break; case "Edgeville": bank = Banks.GRAND_EXCHANGE; break; } combat.toggleAutoRetaliate(false); } @Override public int onLoop() throws InterruptedException { if (bank.contains(myPosition())) { stop(false); } else { getWalking().webWalk(bank); } return 700; } this probaly has somemistake but just did a quick edit in notepad lol Edited May 17, 2020 by TheMcPker Quote Link to comment Share on other sites More sharing options...
TheMcPker Posted May 17, 2020 Share Posted May 17, 2020 28 minutes ago, Camaro said: I think something like this is more what you're looking for package core; import javax.swing.JOptionPane; import org.osbot.rs07.api.map.constants.Banks; import org.osbot.rs07.script.Script; import org.osbot.rs07.script.ScriptManifest; @ScriptManifest(name = "Bank Walker", version = 1, author = "Marcus", logo = "", info = "Walks and runs to banks") public class Main extends Script { int task; @Override public void onStart() throws InterruptedException { String userOptions[] = {"Varrock", "Falador", "Edgeville"}; String userChoice = ""+(String)JOptionPane.showInputDialog(null, "Choose a location", "Bank Walker", JOptionPane.PLAIN_MESSAGE, null, userOptions, userOptions[1]); if(userChoice.equals("Varrock")) { task = 1; } else if (userChoice.equals("Falador")) { task = 2; } else if (userChoice.equals("Edgeville")) { task = 3; } else { stop(false); } } @Override public int onLoop() throws InterruptedException { switch (task) { case 1: return taskOne(); case 2: return taskTwo(); case 3: return taskThree(); } return 700; } public int taskOne() throws InterruptedException { if (Banks.GRAND_EXCHANGE.contains(myPosition())) { stop(false); } else { combat.toggleAutoRetaliate(false); getWalking().webWalk(Banks.GRAND_EXCHANGE); } return 700; } public int taskTwo() throws InterruptedException { if (Banks.FALADOR_WEST.contains(myPosition())) { stop(false); } else { combat.toggleAutoRetaliate(false); getWalking().webWalk(Banks.FALADOR_WEST); } return 700; } public int taskThree() throws InterruptedException { if (Banks.EDGEVILLE.contains(myPosition())) { stop(false); } else { combat.toggleAutoRetaliate(false); getWalking().webWalk(Banks.EDGEVILLE); } return 700; } } how did you get scripter 2 rank? they aren't even diffrent tasks. so the name task makes no sence. or the way that its done Quote Link to comment Share on other sites More sharing options...
Camaro Posted May 17, 2020 Share Posted May 17, 2020 1 minute ago, TheMcPker said: how did you get scripter 2 rank? they aren't even diffrent tasks. so the name task makes no sence. or the way that its done the 'Task' represent the only task that will be performed throughout the entirety of the script, which is chosen by the dialog that shows at the beginning of the script. Also, they are different tasks. Each function webwalks to a different bank. What are you on about? Quote Link to comment Share on other sites More sharing options...
TheMcPker Posted May 17, 2020 Share Posted May 17, 2020 Just now, Camaro said: the 'Task' represent the only task that will be performed throughout the entirety of the script, which is chosen by the dialog that shows at the beginning of the script. Also, they are different tasks. Each function webwalks to a different bank. What are you on about? Every "task" is the exact same code using a diffrent varible area so no its just walk to bank with only diffrence being the bank that you'd be walking to to call it a task would be correct but no its not diffrent tasks Quote Link to comment Share on other sites More sharing options...
Camaro Posted May 17, 2020 Share Posted May 17, 2020 11 minutes ago, TheMcPker said: Every "task" is the exact same code using a diffrent varible area so no its just walk to bank with only diffrence being the bank that you'd be walking to to call it a task would be correct but no its not diffrent tasks I hope you realize I only slightly edited his code so it would actually work Quote Link to comment Share on other sites More sharing options...
TheMcPker Posted May 17, 2020 Share Posted May 17, 2020 1 minute ago, Camaro said: I hope you realize I only slightly edited his code so it would actually work than why are you defending for your choice of code? instead of just saying that you just did a quick edit also im pretty sure the code you edited took more time than doing it proppery it was just a quick delete of 3 methods + change of varible and then a switch statement instead of the if else code you already made a switch statement even. tl:dr don't defend your code when its bad and just say it was a quick edit. Quote Link to comment Share on other sites More sharing options...
Camaro Posted May 17, 2020 Share Posted May 17, 2020 Just now, TheMcPker said: than why are you defending for your choice of code? instead of just saying that you just did a quick edit also im pretty sure the code you edited took more time than doing it proppery it was just a quick delete of 3 methods + change of varible and then a switch statement instead of the if else code you already made a switch statement even. tl:dr don't defend your code when its bad and just say it was a quick edit. Pretty sure hes wondering more about how tasks work in general, which your answer fails to do Quote Link to comment Share on other sites More sharing options...
TheMcPker Posted May 17, 2020 Share Posted May 17, 2020 4 minutes ago, Camaro said: Pretty sure hes wondering more about how tasks work in general, which your answer fails to do you are showing how tasks works in probaly the worst ways possible you are correct in using a switch statement but atleast if your goal truly is to help understand how tasks work than type a quick wcing script example takes 2-3 mins at max and show how to build that properly instead of using 3 identical methods as completly diffrent tasks as a example of how tasks works.. show how to progress between tasks ect you just showed a new scripter that its okay to not use methods propperly great job. Quote Link to comment Share on other sites More sharing options...
Lol_marcus Posted May 17, 2020 Author Share Posted May 17, 2020 I don't get the argument, what's happening lol? The code Camaro provided works fine, what's the issue? o_O Quote Link to comment Share on other sites More sharing options...
TheMcPker Posted May 17, 2020 Share Posted May 17, 2020 4 minutes ago, Lol_marcus said: I don't get the argument, what's happening lol? The code Camaro provided works fine, what's the issue? o_O his code isn't clean or good for long run thats what the argument was about. Quote Link to comment Share on other sites More sharing options...
Camaro Posted May 17, 2020 Share Posted May 17, 2020 4 minutes ago, TheMcPker said: his code isn't clean or good for long run thats what the argument was about. What I put is perfectly fine for someone who is beginning to learn how to do different tasks in the same script. Its the 'state' style. Whats so bad about it for a beginner? Quote Link to comment Share on other sites More sharing options...