herojord Posted September 19, 2015 Share Posted September 19, 2015 (edited) Hi guys, Can someone explain or show me how I can use a switch to walk random paths. how can I add arrays to this. public void Walkpath() throws InterruptedException { switch (random(1, 5)) { case 1: //path1 break; case 2: //path2 break; case 3: break; } sleep(random(700, 1800)); } Edited September 19, 2015 by herojord Quote Link to comment Share on other sites More sharing options...
Tom Posted September 19, 2015 Share Posted September 19, 2015 Hi guys, Can someone explain or show me how I can use a switch to walk random paths. how can I add arrays to this. public void Walkpath() throws InterruptedException { switch (random(1, 5)) { case 1: //path1 break; case 2: //path2 break; case 3: break; } sleep(random(700, 1800)); } public void Walkpath() throws InterruptedException { switch (random(1, 5)) { case 1: getLocalWalker().walk(new Position(x, y, z)); break; case 2: getLocalWalker().walk(new Position(x, y, z)); break; case 3: break; } sleep(random(700, 1800)); } Not sure what else you mean, perhaps try to explain it a bit better? 1 Quote Link to comment Share on other sites More sharing options...
Bobrocket Posted September 19, 2015 Share Posted September 19, 2015 (edited) If you want to walk multiple paths, you could have a data structure like so: public class Path { private List<Position> path; public Path(List<Position> ourPath) { path = ourPath; } public List<Position> getPath() { return path; } } And then you can have something like this: List<Path> ourPaths = new ArrayList<Path>(); ourPaths.add(new Path(Arrays.asList(new Position[]{ new Position(x, y, z), new Position(x, y, z) })); Then, you wouldn't even need a switch/case selection. You could just do: getLocalWalker().walkPath(ourPaths.get(random(1, 5)).getPath()); Edited September 19, 2015 by Bobrocket 3 Quote Link to comment Share on other sites More sharing options...
Flamezzz Posted September 19, 2015 Share Posted September 19, 2015 Could also just use an array like this Position[][] paths = new Position[][] { { new Position(0,0,0), new Position(0,0,0) //path 0 }, { new Position(0,0,0), new Position(0,0,0) //path 1 } }; Position[] myPath = paths[random(0, paths.length-1)]; 2 Quote Link to comment Share on other sites More sharing options...
herojord Posted September 19, 2015 Author Share Posted September 19, 2015 (edited) If you want to walk multiple paths, you could have a data structure like so: public class Path { private List<Position> path; public Path(List<Position> ourPath) { path = ourPath; } public List<Position> getPath() { return path; } } And then you can have something like this: List<Path> ourPaths = new ArrayList<Path>(); ourPaths.add(new Path(Arrays.asList(new Position[]{ new Position(x, y, z), new Position(x, y, z) })); Then, you wouldn't even need a switch/case selection. You could just do: getLocalWalker().walkPath(ourPaths.get(random(1, 5)).getPath()); Thanks this is what I mean. But I will get into this when I'm more experienced in Java. Could also just use an array like this Position[][] paths = new Position[][] { { new Position(0,0,0), new Position(0,0,0) //path 0 }, { new Position(0,0,0), new Position(0,0,0) //path 1 } }; Position[] myPath = paths[random(0, paths.length-1)]; This is more basic so I'll use this untill I'm able to optimize my code and make it more clever. Thankyou. Edited September 19, 2015 by herojord Quote Link to comment Share on other sites More sharing options...
herojord Posted September 19, 2015 Author Share Posted September 19, 2015 Could also just use an array like this Position[][] paths = new Position[][] { { new Position(0,0,0), new Position(0,0,0) //path 0 }, { new Position(0,0,0), new Position(0,0,0) //path 1 } }; Position[] myPath = paths[random(0, paths.length-1)]; I tried using this method, but since I'm working with cases it keeps looping so it never reaches the second value of the array. because myPath gets a diff number everytime it enters the walking case. How can I solve this issue? Quote Link to comment Share on other sites More sharing options...
Flamezzz Posted September 19, 2015 Share Posted September 19, 2015 (edited) I tried using this method, but since I'm working with cases it keeps looping so it never reaches the second value of the array. because myPath gets a diff number everytime it enters the walking case. How can I solve this issue? I'm not sure what this issue is, and I'm also not sure what those cases would be since indexing an array means you don't have to use a switch anymore for this. Perhaps I can help if you show some of your code. Edited September 19, 2015 by Flamezzz Quote Link to comment Share on other sites More sharing options...
herojord Posted September 19, 2015 Author Share Posted September 19, 2015 (edited) I'm not sure what this issue is, and I'm also not sure what those cases would be since indexing an array means you don't have to use a switch anymore for this. Perhaps I can help if you show some of your code.Im on my tablet but my script works like this(!ores && not at bank) Case: walking to bank (ores && not at furnace) Case : walking to furnace (!ores && at bank) Case : banking (ores && at furnace) Case : smelting So the switch keeps calling the path arrays. Edited September 19, 2015 by herojord Quote Link to comment Share on other sites More sharing options...
Chris Posted September 20, 2015 Share Posted September 20, 2015 if (randomPath == 0) { log("random = 0"); randomPath = random(1,4); } if(randomPath == 1) { localWalker.walkPath(pathToHouseTwo); sleep(100 + random (100, 200)); while(myPlayer().isMoving() || myPlayer().isAnimating()) { sleep(400 + random (100, 200)); } return 200 + gRandom(200, 400.0D); } else if (randomPath == 2) { localWalker.walkPath(pathToHouseTwo2); sleep(100 + random (100, 200)); while(myPlayer().isMoving() || myPlayer().isAnimating()) { sleep(400 + random (100, 200)); } return 200 + gRandom(200, 400.0D); } else if (randomPath == 3) { localWalker.walkPath(pathToHouseTwo3); sleep(100 + random (100, 200)); while(myPlayer().isMoving() || myPlayer().isAnimating()) { sleep(400 + random (100, 200)); } return 200 + gRandom(200, 400.0D); } else if (randomPath == 4) { localWalker.walkPath(pathToHouseTwo4); sleep(100 + random (100, 200)); while(myPlayer().isMoving() || myPlayer().isAnimating()) { sleep(400 + random (100, 200)); } return 200 + gRandom(200, 400.0D); } Quote Link to comment Share on other sites More sharing options...
fixthissite Posted September 20, 2015 Share Posted September 20, 2015 (edited) if (randomPath == 0) { log("random = 0"); randomPath = random(1,4); } if(randomPath == 1) { localWalker.walkPath(pathToHouseTwo); sleep(100 + random (100, 200)); while(myPlayer().isMoving() || myPlayer().isAnimating()) { sleep(400 + random (100, 200)); } return 200 + gRandom(200, 400.0D); } else if (randomPath == 2) { localWalker.walkPath(pathToHouseTwo2); sleep(100 + random (100, 200)); while(myPlayer().isMoving() || myPlayer().isAnimating()) { sleep(400 + random (100, 200)); } return 200 + gRandom(200, 400.0D); } else if (randomPath == 3) { localWalker.walkPath(pathToHouseTwo3); sleep(100 + random (100, 200)); while(myPlayer().isMoving() || myPlayer().isAnimating()) { sleep(400 + random (100, 200)); } return 200 + gRandom(200, 400.0D); } else if (randomPath == 4) { localWalker.walkPath(pathToHouseTwo4); sleep(100 + random (100, 200)); while(myPlayer().isMoving() || myPlayer().isAnimating()) { sleep(400 + random (100, 200)); } return 200 + gRandom(200, 400.0D); } Didn't really read through the code, but I noticed you are not using a switch statememt. Why not? Edited September 20, 2015 by fixthissite Quote Link to comment Share on other sites More sharing options...
Chris Posted September 20, 2015 Share Posted September 20, 2015 Didn't really read through the code, but I noticed you are not using a switch statememt. Why not? Because Meh Quote Link to comment Share on other sites More sharing options...
FrostBug Posted September 20, 2015 Share Posted September 20, 2015 (edited) +1 Flamezzz' solution. Simple and effective I tried using this method, but since I'm working with cases it keeps looping so it never reaches the second value of the array. because myPath gets a diff number everytime it enters the walking case. How can I solve this issue? You could probably make use of LocalWalker#walkPath instead; or maintain a global value to keep track of progress in your path walking. The first is probably the better way (tho I haven't actually tried it myself) Edited September 20, 2015 by FrostBug Quote Link to comment Share on other sites More sharing options...
zeroter5 Posted March 17, 2017 Share Posted March 17, 2017 On 9/19/2015 at 8:02 AM, Bobrocket said: If you want to walk multiple paths, you could have a data structure like so: public class Path { private List<Position> path; public Path(List<Position> ourPath) { path = ourPath; } public List<Position> getPath() { return path; } } And then you can have something like this: List<Path> ourPaths = new ArrayList<Path>(); ourPaths.add(new Path(Arrays.asList(new Position[]{ new Position(x, y, z), new Position(x, y, z) })); Then, you wouldn't even need a switch/case selection. You could just do: getLocalWalker().walkPath(ourPaths.get(random(1, 5)).getPath()); I tried implementing this class and these methods but getLocalWalk() and walkPath are undefined for more, what do I need to import in order to fix that? Quote Link to comment Share on other sites More sharing options...
Juggles Posted March 17, 2017 Share Posted March 17, 2017 1 hour ago, zeroter5 said: I tried implementing this class and these methods but getLocalWalk() and walkPath are undefined for more, what do I need to import in order to fix that? Holy grave dig 1 Quote Link to comment Share on other sites More sharing options...