saintpaul1 Posted May 22, 2023 Share Posted May 22, 2023 So im quite new to writing scripts, maybe 3 months i've been practicing. First starting off like most, run everything in onLoop , then i started with some bigger scripts and learned how to use task. The problem i have is that still using task i find myself using dozens and dozens of booleans to trigger certain tasks to make sure nothing overlaps so that i don't have more than one task running at a time.  Basically im just asking if anyone has any pointers for me on structure Thank you. Quote Link to comment Share on other sites More sharing options...
FushigiBot Posted May 23, 2023 Share Posted May 23, 2023 It really depends on the type of script you are trying to make, but a general rule is to use Classes to instance major portions of the script that differ greatly from others. 2 Quote Link to comment Share on other sites More sharing options...
Czar Posted May 23, 2023 Share Posted May 23, 2023 Try and split everything up into smaller tasks, I currently do this for my minigame scripts I have a class for each activity in the script: For my minigame scripts I use states so once you enter the craft runes state it will stay there until isAllowToLeave() is triggered, and I set each state manually in the onloop. 2 1 Quote Link to comment Share on other sites More sharing options...
shaba123 Posted May 23, 2023 Share Posted May 23, 2023 (edited) 4 hours ago, Czar said: Try and split everything up into smaller tasks, I currently do this for my minigame scripts I have a class for each activity in the script: For my minigame scripts I use states so once you enter the craft runes state it will stay there until isAllowToLeave() is triggered, and I set each state manually in the onloop. Ah brill thank you  I have never tried using state so i will get learning thank you  Edit: Could you share an example please? Edited May 23, 2023 by shaba123 Quote Link to comment Share on other sites More sharing options...
Bjotorsflav Posted May 24, 2023 Share Posted May 24, 2023 On 5/22/2023 at 10:00 PM, saintpaul1 said: So im quite new to writing scripts, maybe 3 months i've been practicing. First starting off like most, run everything in onLoop , then i started with some bigger scripts and learned how to use task. The problem i have is that still using task i find myself using dozens and dozens of booleans to trigger certain tasks to make sure nothing overlaps so that i don't have more than one task running at a time.  Basically im just asking if anyone has any pointers for me on structure Thank you. Use the Task system effectively: The Task system in OSBot is designed to handle different tasks independently. Instead of relying solely on booleans to control task execution, consider breaking down your script into smaller, modular tasks. Each task should have a clear purpose and be responsible for a specific action or set of actions. This approach can help you organize your code better and reduce the need for numerous flags. Utilize the sleepUntil condition: The sleepUntil condition is a powerful tool in OSBot that allows you to pause the script execution until a certain condition is met. Instead of using busy waiting loops with booleans, you can use sleepUntil to wait for specific conditions before proceeding to the next task. This can help you synchronize tasks and prevent overlapping. Implement task dependencies: If you have tasks that rely on the completion of other tasks, you can establish task dependencies. By setting up dependencies, you ensure that a task is only executed when its prerequisite tasks have finished. This can help you maintain a sequential flow and avoid conflicts between tasks. Consider using state machines: State machines provide a structured approach to handling different states and transitions within your script. You can define states that represent different phases or conditions of your script, and transitions that dictate when and how the script moves from one state to another. State machines can help you manage complex script logic and minimize the use of booleans. Plan and design your script beforehand: Before diving into writing code, spend some time planning and designing the structure of your script. Identify the different tasks, their dependencies, and the overall flow of your script. Having a clear plan in mind will make it easier to implement an organized structure from the beginning and avoid excessive use of booleans. Remember, scripting is a learning process, and it's normal to iterate and refine your code as you gain experience. Don't be afraid to experiment with different approaches and techniques to find what works best for your specific script. Additionally, engaging with the OSBot community can provide valuable insights and feedback from experienced scripters who can offer further guidance. 1 Quote Link to comment Share on other sites More sharing options...
xlDino Posted May 24, 2023 Share Posted May 24, 2023 22 hours ago, shaba123 said: Ah brill thank you  I have never tried using state so i will get learning thank you  Edit: Could you share an example please?  this might help you get started, PM with any questions 1 Quote Link to comment Share on other sites More sharing options...