JKreas Posted July 6, 2019 Share Posted July 6, 2019 Hey there, I'm working on my third script and I notice that I have had just the main class Java file for my first two scripts. For a lot of the open source scripts I learned from, people had TaskHandlers and seperate files to the point where they had folder organization for the whole script. Am I missing something, or are my scripts probably just too simple to need additional files? I've done a bucket collector from Lumby bank, seaweed picker, and fish cooker in Burthy. Cheers Quote Link to comment Share on other sites More sharing options...
HeyImJamie Posted July 6, 2019 Share Posted July 6, 2019 It generally depends on the complexity of the script you're making and how you like to code. You're only coding for OSRS, so it's easy to pick up bad practices, and it generally doesn't matter too much. For example, a zulrah killer's been written in a singe class before, but it's just horrific to maintain. Find something that works for you Quote Link to comment Share on other sites More sharing options...
Ragboys is back Posted July 6, 2019 Share Posted July 6, 2019 I believe that, the more complex a script is, the more organization you must have for it (this mean more classes and shit) I don't see how the scripts you mentioned would need to have lots of classes, unless you wanna make your own walking, your own methods to cook, pick stuff up, but that would be a time you wouldn't need to consume cuz the osbot API is rich enough and can provide everything you need. Quote Link to comment Share on other sites More sharing options...
Hybris Posted July 8, 2019 Share Posted July 8, 2019 For the scripts you are describing it wouldn't be a problem to have everything in one class, but it's always nice to separate actions or tasks (like banking) from the main class when it gets a little more complex. This way you can easily adapt it when necessary & find/fix bugs. The general idea is that you can look back at the script in 2 years & still understand it while at the same time being readable/adaptable for another scripter (even if that'll never happen). Commenting your code helps with that too. This is also an interesting read for any script that you want to be expendable (or is big in general): Quote Link to comment Share on other sites More sharing options...
Chorux Posted July 9, 2019 Share Posted July 9, 2019 I feel like that for small scripts, and for other small programs too, it does not matter how you organize your code as it most likely will only have some hundred lines of code. However, if your script is bigger or could eventually become bigger it's good to at least try to follow the single responsibility principle, which basically means that one class should be responsible of one functionality/feature. For example one functionality could be banking, pathing or a break manager. Not only will this help with organizing your code, but you might get some reusable modules which you can use in your other scripts. If you want to do even more or just learn what you could do, check out SOLID design principles. Quote Link to comment Share on other sites More sharing options...
Apaec Posted July 9, 2019 Share Posted July 9, 2019 Often, a single class is enough, but for larger projects you might need to take advantage of object oriented design principles. While most scripts can make good use of object orientation, it is typically AIO scripts which make best use of it, as abstracting away details such as specific string values becomes really powerful. As an example of this, here's the source code for my AIO Herblore script (available on the SDN) for you to peruse: https://github.com/apaec/aio-herblore 1 Quote Link to comment Share on other sites More sharing options...