Zunarb Posted August 22, 2020 Share Posted August 22, 2020 Okay so what am i doing wrong here? It opens up the tab to choose the spell but it does not pick the fire bolt based on its widget. It keeps thinking that fire bolt is null even tho the tab for it is open? Trying to setup it up to autocast for a staff. public void attackStyle() throws InterruptedException { RS2Widget fireBolt = getWidgets().get(201,1,8); RS2Widget spellChoise = getWidgets().get(593,28); if (getSkills().getDynamic(Skill.MAGIC) >= 35) { getTabs().open(Tab.ATTACK); sleep(1000); spellChoise.interact("Choose spell"); sleep(1000); if (fireBolt != null) { log("Selecting fire bolt"); fireBolt.interact("Fire Bolt"); } } } Quote Link to comment Share on other sites More sharing options...
Kramnik Posted August 22, 2020 Share Posted August 22, 2020 Hi, you dont need to use widgets to cast spells. There is a Magic API https://osbot.org/api/org/osbot/rs07/api/Magic.html Quote Link to comment Share on other sites More sharing options...
Zunarb Posted August 22, 2020 Author Share Posted August 22, 2020 10 minutes ago, Kramnik said: Hi, you dont need to use widgets to cast spells. There is a Magic API https://osbot.org/api/org/osbot/rs07/api/Magic.html The problem is not casting a spell, the problem is setting up a spell for autocast on a staff Atleast i coudnt figure out any magic API that worked in the situation for me. Quote Link to comment Share on other sites More sharing options...
BravoTaco Posted August 22, 2020 Share Posted August 22, 2020 (edited) RS2Widget fireBolt = getWidgets().get(201,1,8); RS2Widget spellChoise = getWidgets().get(593,28); if (getSkills().getDynamic(Skill.MAGIC) >= 35) { getTabs().open(Tab.ATTACK); What appears to be happening is that you are setting the variable too soon. You set it before opening the tab, when you to set it after you have verified that the tab is open. Edited August 22, 2020 by BravoTaco Quote Link to comment Share on other sites More sharing options...
OsPlay Posted August 22, 2020 Share Posted August 22, 2020 (edited) I'm not an expert, i didn't test it, but i supouse that i'll do like: public void attackStyle() throws InterruptedException { if (getSkills().getDynamic(Skill.MAGIC) >= 35) { // open the tab... getTabs().open(Tab.ATTACK); // wait until tab is open... new ConditionalSleep(5000){ @Override public boolean condition() throws InterruptedException { if(getWidgets().isVisible(593,28)) return true; return getTabs().isOpen(Tab.ATTACK); } }.sleep(); // failed to see widget? if(!getWidgets().isVisible(593,28)) return; // take the widget. RS2Widget spellChoise = getWidgets().get(593,28); // interact with the widget. spellChoise.interact("Choose spell"); // sleep until can see the widget. new ConditionalSleep(5000){ @Override public boolean condition() throws InterruptedException { return getWidgets().isVisible(201,1,8); } }.sleep(); // failed to see widget? if(!getWidgets().isVisible(201,1,8)) return; // take the widget. RS2Widget fireBolt = getWidgets().get(201,1,8); if (fireBolt != null) { log("Selecting fire bolt"); fireBolt.interact("Fire Bolt"); } } Edited August 22, 2020 by OsPlay i put don't when is past, i didn't* Quote Link to comment Share on other sites More sharing options...
Zunarb Posted August 22, 2020 Author Share Posted August 22, 2020 29 minutes ago, BravoTaco said: RS2Widget fireBolt = getWidgets().get(201,1,8); RS2Widget spellChoise = getWidgets().get(593,28); if (getSkills().getDynamic(Skill.MAGIC) >= 35) { getTabs().open(Tab.ATTACK); What appears to be happening is that you are setting the variable too soon. You set it before opening the tab, when you to set it after you have verified that the tab is open. Thank you for pointing that out! After i fixed the variable timing it started working perfectly now Quote Link to comment Share on other sites More sharing options...
BravoTaco Posted August 22, 2020 Share Posted August 22, 2020 1 hour ago, Zunarb said: Thank you for pointing that out! After i fixed the variable timing it started working perfectly now Np. Quote Link to comment Share on other sites More sharing options...