candlemagnifico Posted August 21, 2019 Share Posted August 21, 2019 Hello, I want to try my hands at more complicated scripts now that I've made one, but I'm very unsure of how to go about separating out the logic for different actions or states that I expect my bot to encounter. I'd like to have a separate class for each state that my bot will exist in, but I'm not sure how to relate that to the main onLoop method inherited from Script Any suggestions? Quote Link to comment Share on other sites More sharing options...
ExtraBotz Posted August 22, 2019 Share Posted August 22, 2019 I did something similar in my open source quest bot here: The first thing you should know is that when exiting the main loop you aren't updating the game variables until the loop cycles again. That means you can't execute all your game logic in another loop. You will need to continue this original loop at the end of your method execution. As for creating different classes are you trying to execute different logic in these classes? If so you might be better off just using methods rather than passing state back and fourth between classes. When you instantiate a class you're creating an object which has its own identity, state, and behavior. What I do in my script: Each quest is a class and they all have a template (an abstract class called QuestObject) with a method called "run()". In the main loop I use polymorphism to pass whatever quest is running to a QuestObject. Using this object (that can be any quest) I execute the "run()" method which is mandatory for all quests. Inside the "run()" method I execute any logic for that specific quest. The "run()" method returns a number to the main loop (0 - 3 usually). In the main loop I use an integer variable called "status" that holds the returned value from the quest "run()" method. I run a switch method based on the "status" variable. 1 -> continue running the "run()" method 2 -> the quest is finished so execute the next quest 3 -> there was an error, stop the script. Then the loop continues. Quote Link to comment Share on other sites More sharing options...
candlemagnifico Posted August 22, 2019 Author Share Posted August 22, 2019 This seems more than good. I'll try this method for my next project and see how it goes. Thanks mate. Quote Link to comment Share on other sites More sharing options...