why paranoid Posted January 17, 2019 Posted January 17, 2019 (edited) Hello, I'm new to osrs scripting and having trouble getting a simple pray pot drinker to work. Here is a snippet: public final int onLoop() throws InterruptedException { // drinks potion when prayer falls under 10. if (getSkills().getDynamic(Skill.PRAYER) < 10){ drinkPotion(); } return 0; } public void drinkPotion(){ // if slot contains prayer pot, it is drank and loop is exited. for (int i = 0; i <= 28; i++) { if (getInventory().getItemInSlot(i).nameContains("Prayer potion(4)", "Prayer potion(3)", "Prayer potion(2)", "Prayer potion(1)")) { getInventory().interact(i, "Drink"); break; } } } Program works perfectly without the conditional that prayer be under 10. With it, once the conditional is met, the client (not the game) freezes. Any help would be appreciated, thanks. EDIT: was a simple counting from zero error. (should be <=27) Edited January 17, 2019 by why paranoid
Spider Scripts Posted January 17, 2019 Posted January 17, 2019 (edited) make onloop return 300, so that it repeats itself every 300 milliseconds or so also in osbot API slots are numbered from 0-27 so make the loop <28 instead of <= also check the logger it usually can give you hints about what is going wrong Edited January 17, 2019 by Spider
FuryShark Posted January 17, 2019 Posted January 17, 2019 3 minutes ago, Spider said: make onloop return 300, so that it repeats itself every 300 milliseconds or so also in osbot API slots are numbered from 0-27 so make the loop <28 instead of <= also check the logger it usually can give you hints about what is going wrong He edited it an hour ago
Spider Scripts Posted January 17, 2019 Posted January 17, 2019 35 minutes ago, FuryShark said: He edited it an hour ago ohhh nvm didn't see the edit just focused on the code
HeyImJamie Posted January 18, 2019 Posted January 18, 2019 2 hours ago, FuryShark said: He edited it an hour ago I'd still add a sleep. It's iterating far too fast for what it should, surprised it's even running tbh.
Explv Posted January 18, 2019 Posted January 18, 2019 11 hours ago, why paranoid said: Hello, I'm new to osrs scripting and having trouble getting a simple pray pot drinker to work. Here is a snippet: public final int onLoop() throws InterruptedException { // drinks potion when prayer falls under 10. if (getSkills().getDynamic(Skill.PRAYER) < 10){ drinkPotion(); } return 0; } public void drinkPotion(){ // if slot contains prayer pot, it is drank and loop is exited. for (int i = 0; i <= 28; i++) { if (getInventory().getItemInSlot(i).nameContains("Prayer potion(4)", "Prayer potion(3)", "Prayer potion(2)", "Prayer potion(1)")) { getInventory().interact(i, "Drink"); break; } } } Program works perfectly without the conditional that prayer be under 10. With it, once the conditional is met, the client (not the game) freezes. Any help would be appreciated, thanks. EDIT: was a simple counting from zero error. (should be <=27) The for loop is redundant, the script is already looping, so you can just call interact(filter) and it will progress through the inventory. As everyone else suggested, you should add a sleep after the interact to wait for the potion to actually be consumed before trying to drink the next one.
Reminiscence Posted January 19, 2019 Posted January 19, 2019 (edited) public void timer(boolean why) { new ConditionalSleep(10000) { @Override public boolean condition() throws InterruptedException { return why; } }.sleep(); } if (skills.getDynamic(Skill.PRAYER) <= randomPrayerNum && inventory.contains(new ContainsNameFilter<>("Prayer"))) { inventory.getItem(new ContainsNameFilter<>("Prayer")).interact(); timer(skills.getDynamic(Skill.PRAYER) > randomPrayerNum); randomPrayerNum = random(10, 35); } First part is it's own method, second part can be either added to your loop, or it's own method. Also, if you're doing nameContains, you don't need to specify the entire name. Just "Prayer pot" would work. Edited January 19, 2019 by qmqz