Jump to content

Advice on structuring large scripts?


saintpaul1

Recommended Posts

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.

Link to comment
Share on other sites

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.

LY1ne5c.png

Ve5FrdP.png

  • Like 2
  • Heart 1
Link to comment
Share on other sites

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.

LY1ne5c.png

Ve5FrdP.png

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 by shaba123
Link to comment
Share on other sites

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.

  1. 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.

  2. 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.

  3. 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.

  4. 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.

  5. 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.

  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...