kingbutton Posted August 15, 2017 Share Posted August 15, 2017 I'm learning how to interact with items in the inventory. Also trying to learn how to interact with items on the ground. When I run the code, my OsBot freezes, and I have to task manager to close it. Here's what I have at the moment. import org.osbot.rs07.api.model.RS2Object; import org.osbot.rs07.script.Script; import org.osbot.rs07.script.ScriptManifest; import org.osbot.rs07.utility.ConditionalSleep; @ScriptManifest(author = "Kingbutton", info = "Fire Cooking", logo = "", name = "LumbCook", version = 0) public class Main extends Script { @Override public int onLoop() throws InterruptedException { if (fireCheck()) { log("hello bitch"); } else { makeFire(); } return 50; } public boolean fireCheck() { RS2Object fire = objects.closest("Fire"); if (fire != null) { return true; } else { return false; } } public void makeFire() { if (!myPlayer().isAnimating() && !myPlayer().isMoving()) { RS2Object log = objects.closest("Logs"); if (log.interact("Light")) { new ConditionalSleep(random(600, 1200)) { @Override public boolean condition() throws InterruptedException { return myPlayer().isAnimating(); } }.sleep(); } } } } Quote Link to comment Share on other sites More sharing options...
Chris Posted August 15, 2017 Share Posted August 15, 2017 Quote Link to comment Share on other sites More sharing options...
kingbutton Posted August 15, 2017 Author Share Posted August 15, 2017 (edited) 11 minutes ago, Chris said: Not 100% what you meant by this, But I took my guess. This is the change I made. import org.osbot.rs07.api.model.RS2Object; import org.osbot.rs07.script.Script; import org.osbot.rs07.script.ScriptManifest; import org.osbot.rs07.utility.ConditionalSleep; @ScriptManifest(author = "Kingbutton", info = "Fire Cooking", logo = "", name = "LumbCook", version = 0) public class Main extends Script { @Override public int onLoop() throws InterruptedException { makeFire(); return 50; } public void makeFire() { RS2Object fire = objects.closest("Fire"); RS2Object log = objects.closest("Logs"); if (fire != null) { if (!myPlayer().isAnimating() && !myPlayer().isMoving()) { if (log.interact("Light")) { new ConditionalSleep(random(600, 1200)) { @Override public boolean condition() throws InterruptedException { return myPlayer().isAnimating(); } }.sleep(); } } } } } It's not freezing anymore but my code isn't doing anything. So am I using the wrong api to interact with the log that's on the ground? Edited August 15, 2017 by kingbutton Quote Link to comment Share on other sites More sharing options...
Chris Posted August 15, 2017 Share Posted August 15, 2017 o null check b4 interacting if its a ground item use the GroundItem api Quote Link to comment Share on other sites More sharing options...
Chris Posted August 15, 2017 Share Posted August 15, 2017 import org.osbot.rs07.api.model.RS2Object; import org.osbot.rs07.script.Script; import org.osbot.rs07.script.ScriptManifest; import org.osbot.rs07.utility.ConditionalSleep; @ScriptManifest(author = "Kingbutton", info = "Fire Cooking", logo = "", name = "LumbCook", version = 0) public class Main extends Script { @Override public int onLoop() throws InterruptedException { if (fireCheck()) { log("hello bitch"); } else { makeFire(); } return 50; } public boolean fireCheck() { RS2Object fire = objects.closest("Fire"); return fire != null; } public void makeFire() { if (!myPlayer().isAnimating() && !myPlayer().isMoving()) { GroundItem log = getGroundItems().closest("Logs"); if (log != null && log.interact("Light")) { new ConditionalSleep(3000) { @Override public boolean condition() throws InterruptedException { return myPlayer().isAnimating(); } }.sleep(); } } } } Quote Link to comment Share on other sites More sharing options...
kingbutton Posted August 15, 2017 Author Share Posted August 15, 2017 Ight thanks MAN! Can you explain to me why in the fireCheck() method I have to return fire != null. Like why can't i do it in the makeFire() method? Quote Link to comment Share on other sites More sharing options...
d0zza Posted August 15, 2017 Share Posted August 15, 2017 3 hours ago, kingbutton said: Ight thanks MAN! Can you explain to me why in the fireCheck() method I have to return fire != null. Like why can't i do it in the makeFire() method? You can do it in the makeFire() method, For example something like this: public void makeFire() { RS2Object fire = objects.closest("Fire"); if (!myPlayer().isAnimating() && !myPlayer().isMoving() && fire != null) { GroundItem log = getGroundItems().closest("Logs"); if (log != null && log.interact("Light")) { new ConditionalSleep(3000) { @Override public boolean condition() throws InterruptedException { return myPlayer().isAnimating(); } }.sleep(); } } } It's mostly down to preference, however the way you had it before makes it clearer (to me) when you want the script to light a fire. Also at the moment you're trying to interact with logs on the ground. If you want to interact with logs in your inventory do this: Item log = getInventory().getItem("Logs"); Quote Link to comment Share on other sites More sharing options...