Trees Posted November 12, 2016 Share Posted November 12, 2016 I want to make scripts that are more event based rather than loop/conditional sleep based. For example an event like OnInventoryFull or OnBankOpen. To do this, I need to create an event manager to subscribe and fire events, independent of the main script loop. I'm not very familiar with threading in java, and I'm just wondering what the appropriate way to do this is. 1 Quote Link to comment Share on other sites More sharing options...
Team Cape Posted November 12, 2016 Share Posted November 12, 2016 (edited) i would rethink the most efficient way to do this. creating a series of events and managing them in onLoop() doesn't sound very efficient. if i were you, i'd probably use a node-based framework and just run through the nodes, checking if it's the proper time for it to run, and running them if they are Edited November 12, 2016 by Imateamcape Quote Link to comment Share on other sites More sharing options...
Trees Posted November 12, 2016 Author Share Posted November 12, 2016 i would rethink the most efficient way to do this. creating a series of events and managing them in onLoop() doesn't sound very efficient. if i were you, i'd probably use a node-based framework and just run through the nodes, checking if it's the proper time for it to run, and running them if they are Obviously having a second loop running wouldn't be as efficient, but as long as the conditions to fire an event weren't very CPU intensive, I don't think it makes a difference. The problem with node based stuff is if you do have CPU intensive conditions to check through before running the nodes, which could be particularly bad when dealing with needed failsafes within a script. Although I suppose you could organize it so the fail safes are ran first. In general, nodes are considered event driven scripting, if I was going to use this approach I would probably consider behavior trees. Quote Link to comment Share on other sites More sharing options...
Team Cape Posted November 12, 2016 Share Posted November 12, 2016 Obviously having a second loop running wouldn't be as efficient, but as long as the conditions to fire an event weren't very CPU intensive, I don't think it makes a difference. The problem with node based stuff is if you do have CPU intensive conditions to check through before running the nodes, which could be particularly bad when dealing with needed failsafes within a script. Although I suppose you could organize it so the fail safes are ran first. In general, nodes are considered event driven scripting, if I was going to use this approach I would probably consider behavior trees. Regardless, you'd have the same conditions to test before starting an event. If you properly organize your framework and don't have more than 10 nodes (and you shouldnt have more than 5 for even the most intensive script), this would probably be the best way. If anyone has any other ideas, feel free to mention them. Quote Link to comment Share on other sites More sharing options...
Alek Posted November 12, 2016 Share Posted November 12, 2016 Watching your posts over the last month or two, you spend a lot more time thinking about everything else besides making the script itself. Make the script and as you write it, you will know the path you need to take. Some scripts are small and are best suited for simple loop logic, other scripts benefit from Tasks/States. It almost sounds like you are going to university and you're trying to directly apply what you learned into programming. Start simple and expand from there. 2 Quote Link to comment Share on other sites More sharing options...
Trees Posted November 12, 2016 Author Share Posted November 12, 2016 Watching your posts over the last month or two, you spend a lot more time thinking about everything else besides making the script itself. Make the script and as you write it, you will know the path you need to take. Some scripts are small and are best suited for simple loop logic, other scripts benefit from Tasks/States. It almost sounds like you are going to university and you're trying to directly apply what you learned into programming. Start simple and expand from there. Oh I am making scripts, I haven't released anything yet. Mostly for personal and private use. I have about 100 different classes including scripts and utility files in my project. I make scripts for LoL, and did code stuff for RS before that. Along the way I have learned that there is no best or correct way to do something. I have learned that different implementations can work better than what's standard or widely used, in terms of efficiency, output, or something like ban rate. That being said, I do acknowledge that there are a plethora of wrong ways to do things, and direct testing is the best way to check results. Quote Link to comment Share on other sites More sharing options...
Botre Posted November 12, 2016 Share Posted November 12, 2016 If you want your script logic to be driven by an observer-like pattern, your main challenge will not be the implementation of threading but rather the prioritization of the event-handling. Also, using such patterns only make sense if the event you're listening for needs to be processed by multiple handlers, imo this is rarely the case in RS scripting. If your code is hogging too much CPU there are other solutions: - Write more efficient code. - Call your bottleneck code less frequently. The latter can be achieved by using multi threading, but there are much simpler and elegant ways to go about it. If you want specific tips/examples on how to improve your performance, I will gladly help out but I'm going to need some code / context first ^^ Cheers. 1 Quote Link to comment Share on other sites More sharing options...
liverare Posted November 13, 2016 Share Posted November 13, 2016 (edited) Your computer is loop-based: Loop 1 looks for values and stores them. Loop 2 looks for values and compares with loop 1. Loop 2 finds a difference between the previously stored value and the current value, and so fires an event. Event-driven, from my experience, only involves GUIs/UIs because the computer loops and loops until the user interacts with it, then that input is converted into programmatic events which can be responded to. Try using Areas at the core of your logic, because knowing where you are in-game will help you to figure out what you should be doing next. Edited November 13, 2016 by liverare Quote Link to comment Share on other sites More sharing options...