why paranoid Posted January 17, 2019 Share 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 Quote Link to comment Share on other sites More sharing options...
Mr_MilkysButler Posted January 17, 2019 Share Posted January 17, 2019 Output log? Quote Link to comment Share on other sites More sharing options...
Spider Scripts Posted January 17, 2019 Share 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 Quote Link to comment Share on other sites More sharing options...
FuryShark Posted January 17, 2019 Share 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 Quote Link to comment Share on other sites More sharing options...
Spider Scripts Posted January 17, 2019 Share 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 Quote Link to comment Share on other sites More sharing options...
HeyImJamie Posted January 18, 2019 Share 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. Quote Link to comment Share on other sites More sharing options...
Explv Posted January 18, 2019 Share 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. Quote Link to comment Share on other sites More sharing options...
Reminiscence Posted January 19, 2019 Share 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 Quote Link to comment Share on other sites More sharing options...