mauricimoo 2 Posted August 9, 2016 hello, i have this piece of code: case WALKTO: int Choice = Calculations.random(1, 4); switch(Choice) { case 1: getWalking().walk(area1.getRandomTile()); break; case 2: getWalking().walk(area2.getRandomTile()); break; case 3: getWalking().walk(area3.getRandomTile()); break; case 4: getWalking().walk(area4.getRandomTile()); break; } the script does choose one case randomly, but after a few seconds it chooses another case randomly. this results in the player walking back and forth between certain area's, and never actually arriving at one area. how can i make sure the bot chooses a case, and also finishes walking to the area? thanks in advance
Cardozz 46 Posted August 9, 2016 hello, i have this piece of code: case WALKTO: int Choice = Calculations.random(1, 4); switch(Choice) { case 1: getWalking().walk(area1.getRandomTile()); break; case 2: getWalking().walk(area2.getRandomTile()); break; case 3: getWalking().walk(area3.getRandomTile()); break; case 4: getWalking().walk(area4.getRandomTile()); break; } the script does choose one case randomly, but after a few seconds it chooses another case randomly. this results in the player walking back and forth between certain area's, and never actually arriving at one area. how can i make sure the bot chooses a case, and also finishes walking to the area? thanks in advance It's because case WALK_TO gets called again. When it gets called again, it will replace int choice. Also, you should have variables begin with a lowercase. how can i make sure the bot chooses a case, and also finishes walking to the area? case WALKTO: int choice; if(choice == 0){ choice = Calculations.random(1, 4); } switch(choice) { case 1: getWalking().walk(area1.getRandomTile()); break; case 2: getWalking().walk(area2.getRandomTile()); break; case 3: getWalking().walk(area3.getRandomTile()); break; case 4: getWalking().walk(area4.getRandomTile()); break; choice = 0; } something like that.
Dreamlicker 750 Posted August 9, 2016 It's because case WALK_TO gets called again. When it gets called again, it will replace int choice. Also, you should have variables begin with a lowercase. how can i make sure the bot chooses a case, and also finishes walking to the area? ##removed something like that. Why are you checking if choice is 0 and assigning it to 0 again? No need to do that as it will never be 0. Anyways, you'll want to sleep until you are not moving or you are within a certain distance of your chosen area center or some other tile that is near it.
Cardozz 46 Posted August 9, 2016 Why are you checking if choice is 0 and assigning it to 0 again? No need to do that as it will never be 0. Anyways, you'll want to sleep until you are not moving or you are within a certain distance of your chosen area center or some other tile that is near it. Because his getState is probably returning WALK_TO everytime. To generate only a number AFTER the case executed correctly, i assgig the number to 0 so that a new one will be generated when the case gets called again. This will prevent the number changing everytime the WALK_TO case gets called. Read his post: the script does choose one case randomly, but after a few seconds it chooses another case randomly. this results in the player walking back and forth between certain area's, and never actually arriving at one area. how can i make sure the bot chooses a case, and also finishes walking to the area? I understand what you say, but i thought that getWalking() would loop until it actually arrived at the given destination. Didn't know it just loops the case everytime. How would you do it? ???? case WALKTO: int choice; if(choice == 0){ choice = Calculations.random(1, 4); } if(!area1.contains(getLocalPlayer()) || !area2.contains(getLocalPlayer()) || !area3.contains(getLocalPlayer()) || !area4.contains(getLocalPlayer())){ switch(choice) { case 1: getWalking().walk(area1.getRandomTile()); break; case 2: getWalking().walk(area2.getRandomTile()); break; case 3: getWalking().walk(area3.getRandomTile()); break; case 4: getWalking().walk(area4.getRandomTile()); break; } } else { choice = 0; }
Dreamlicker 750 Posted August 9, 2016 Because his getState is probably returning WALK_TO everytime. To generate only a number AFTER the case executed correctly, i assgig the number to 0 so that a new one will be generated when the case gets called again. This will prevent the number changing everytime the WALK_TO case gets called. Read his post: the script does choose one case randomly, but after a few seconds it chooses another case randomly. this results in the player walking back and forth between certain area's, and never actually arriving at one area. how can i make sure the bot chooses a case, and also finishes walking to the area? I understand what you say, but i thought that getWalking() would loop until it actually arrived at the given destination. Didn't know it just loops the case everytime. How would you do it? ???? #removed There's no way for us to know what his code is doing without seeing all of it, so I am making 0 assumptions. .walk() does not loop repeatedly until you reach the destination, that would be really annoying to deal with imo. However, I do see what you are saying. private Area chosenArea; private Area area1; private Area area2; private Area area3; private Area area4; private Area[] areas = {area1, area2, area3, area4}; //ew public int onLoop() { if (!area.contains(getLocalPlayer()) { walkToRandomArea(); } } private void walkToRandomArea() { if (chosenArea == null) { chosenArea = areas[Calculations.random(however you do 0-3 w/ this, I dont use it]; } else { if (getWalking().walk(chosenArea.getRandomTile()) { //This will be ok assuming the area isnt massive. if its massive it may run kinda randomly. sleep(random time); sleepUntil(() -> !getLocalPlayer().isMoving() || getLocalPlayer().distance(getClient().getDestination()) < (random value between maybe like 5 and 10), random time above 4s); } } } I think that makes sense note that you'd have to adapt it to how you structure your scripts.
Cardozz 46 Posted August 10, 2016 There's no way for us to know what his code is doing without seeing all of it, so I am making 0 assumptions. .walk() does not loop repeatedly until you reach the destination, that would be really annoying to deal with imo. However, I do see what you are saying. ##REMOVED I think that makes sense note that you'd have to adapt it to how you structure your scripts. Exactly, i just tried to adapt my advice to his code. I won't do it that way either. HOWEVER: you can't null check an int. Unless you use booleans for chosenArea, it will give errors.
Dreamlicker 750 Posted August 10, 2016 Exactly, i just tried to adapt my advice to his code. I won't do it that way either. HOWEVER: you can't null check an int. Unless you use booleans for chosenArea, it will give errors. chosenArea is an Area =p
Mad 86 Posted August 10, 2016 Just a question, but when you post a script question, we would assume you already know your script loops and re-executes the same actions yes? since a loop just loops over and over, and all the conditions are the same, it is going to do the exact same thing, so what is the question? Is it doing something else?
Recommended Posts
Archived
This topic is now archived and is closed to further replies.