Joseph Posted September 5, 2014 Posted September 5, 2014 How do i add my own listener onto one of my scripts?
Joseph Posted September 5, 2014 Author Posted September 5, 2014 pls elaborate I would like to add in a inventory Listener
Dog_ Posted September 5, 2014 Posted September 5, 2014 I would like to add in a inventory Listener could just run it on a different thread 2
Mysteryy Posted September 6, 2014 Posted September 6, 2014 I would like to add in a inventory Listener If you know how to multithread you can easily make a listener in a new class that implements Runnable. You can basically make this new thread constantly watch your inventory slots and check if anything changes, or whatever you are trying to make it do. Just make a new class that implements Runnable, make that class do whatever you want, then in Script thread, Thread thread = new Thread(ClassName) then start the thread. I haven't used that in a while, but its something like that. Just look up the basics of multi threading and you can easily find how to make it. ^_^
Swizzbeat Posted September 6, 2014 Posted September 6, 2014 Whatever you do, at least add a small sleep in between inventory updates. You don't want to kill your CPU because you want to be notified the exact millisecond your inventory changes. Waiting for even just a second will consume such little resources it won't even make a noticeable impact on the CPU usage of your script.
Joseph Posted September 6, 2014 Author Posted September 6, 2014 Whatever you do, at least add a small sleep in between inventory updates. You don't want to kill your CPU because you want to be notified the exact millisecond your inventory changes. Waiting for even just a second will consume such little resources it won't even make a noticeable impact on the CPU usage of your script. How big of a sleep you think it's good, 200 mil second
Swizzbeat Posted September 6, 2014 Posted September 6, 2014 How big of a sleep you think it's good, 200 mil secondMore like 1200 milliseconds (2 game ticks) unless you absolutely need to be notified of a change right away.
Botre Posted September 6, 2014 Posted September 6, 2014 Just curious, what exactly would it be listening for ? :|
Joseph Posted September 6, 2014 Author Posted September 6, 2014 (edited) Just curious, what exactly would it be listening for ? :| when you have a change of items in the inventory. tbh im still a little confused on how to set it up. Ive tried so many different things Edited September 6, 2014 by josedpay
Botre Posted September 6, 2014 Posted September 6, 2014 (edited) when you have a change of items in the inventory. tbh im still a little confused on how to set it up. Ive tried so many different things If you are going to compare inventories for equality, couldn't you just use these lines (at appropriate places of course,not stacked like this )? Item[] compareThis = getInventory().getItems(); Item[] withThis = getInventory().getItems(); boolean equaliThis = compareThis != null && withThis != null && Arrays.equals(compareThis , withThis); Edited September 6, 2014 by Botrepreneur
Dog_ Posted September 6, 2014 Posted September 6, 2014 when you have a change of items in the inventory. tbh im still a little confused on how to set it up. Ive tried so many different things Cache them and then compare the cache to the current items 1
Swizzbeat Posted September 7, 2014 Posted September 7, 2014 when you have a change of items in the inventory. tbh im still a little confused on how to set it up. Ive tried so many different things Depends what you're attempting to monitor and how you want to receive notifications about changes. This should help you get started (or provide an answer for you): http://osbot.org/forum/topic/51856-inventory-monitor-keep-live-track-of-your-items/
Joseph Posted September 7, 2014 Author 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 -.-