Swizzbeat Posted September 7, 2014 Posted September 7, 2014 I already created my own listener, it just people were telling me to put it in a thread, which make sences. And have the thread loop it's self. So far I have created the thread started it once. And that's it -.- How did you create a listener if it wasn't a thread?
Joseph Posted September 7, 2014 Author Posted September 7, 2014 (edited) How did you create a listener if it wasn't a thread? well i created a test script and had a method from the listener class loop within the onloop. But since it was a test and there wasnt anything else in the onloop. It was fine. But once i add it into my crafter, i noticed it will excute the listener, then execute the actual on loop. Which wasnt what i wanted. Then i started reading about threads, and i didnt know that when a thread starts it will execute the Run method in the class that implement runnable. Which i had So im guessing this is where i will need the loop, people were telling me about. edit: i guess not lol -.- Edited September 7, 2014 by josedpay
Joseph Posted September 7, 2014 Author Posted September 7, 2014 If anybody wants to help, i would appreciate it
Botre Posted September 7, 2014 Posted September 7, 2014 package _test; import java.util.Arrays; import org.osbot.rs07.api.model.Item; import org.osbot.rs07.api.util.ItemContainer; public class ContainerListener implements Runnable { private final ItemContainer container; private Item[] cache; private boolean changed; public ContainerListener(ItemContainer container) { this.container = container; } public void setCache() { cache = container.getItems(); changed = false; } @Override public void run() { changed = Arrays.equals(cache, container.getItems()); try { Thread.sleep(1200); } catch (InterruptedException e) { e.printStackTrace(); } } public boolean getChanged() { return changed; } } ContainerListener inventoryListener = new ContainerListener(getInventory()); This most likely won't work as it is, but might inspire you or something ^^
Joseph Posted September 7, 2014 Author Posted September 7, 2014 package _test; import java.util.Arrays; import org.osbot.rs07.api.model.Item; import org.osbot.rs07.api.util.ItemContainer; public class ContainerListener implements Runnable { private final ItemContainer container; private Item[] cache; private boolean changed; public ContainerListener(ItemContainer container) { this.container = container; } public void setCache() { cache = container.getItems(); changed = false; } @Override public void run() { changed = Arrays.equals(cache, container.getItems()); try { Thread.sleep(1200); } catch (InterruptedException e) { e.printStackTrace(); } } public boolean getChanged() { return changed; } } ContainerListener inventoryListener = new ContainerListener(getInventory()); This most likely won't work as it is, but might inspire you or something ^^ shouldnt the run method contain a loop?
Botre Posted September 7, 2014 Posted September 7, 2014 shouldnt the run method contain a loop? Derp'd. Just stick its contents in a while loop