Jump to content

The just use onLoop() bro


Hayase

Recommended Posts

When someone talks about task based script or enum based scripts there's always that other guy: Just use onloop bro!

What does that mean though?

Well first off you can think of it as normal scripting--it's not new!

For an example take a look at this onloop()

    /**
     * Just use onLoop() bro
     *
     * @return the loop interval
     * @throws InterruptedException if something fucks up
     */
    @Override
    public int onLoop() throws InterruptedException {
        if (!inventory.isFull() && cows.cowsNearby()) {
            status = "At work--picking up bones and hides...";
            bone.pickupBones();
            hide.collectHides();
            hideCount = hide.getHideCount();
            boneCount = bone.getBonerCount();
        } else if (inventory.isFull()) {
            status = "Time to bank";
            goToBank.walkToBank();
        } else if (!cows.cowsNearby() && inventory.isEmpty()) {
            status = "Walking to cows for more loot";
            cows.walkToCows();
        }
        return random(200, 300);
    }

It's small and concise. One could read it and understand what is going to be happening.

Start from the top and work your way down:

  1. Inventory not full and cows nearby? Pickup some shit.
  2. Inventory full? Go bank
  3. Inventory not full and no cows nearby? FIND DEM COWS!

It's easy to read, right?

Just use onloop() bro

Full project has been uploaded to this thread

Bank.java

CollectBoners.java

CollectHide.java

Main.java

WalkToCows.java

Edited by Hayase
  • Like 2
Link to comment
Share on other sites

  • 4 weeks later...

Tasks based approaches are nice but I prefer trees. Made a "TreeMember" class and "TreeBranch" and "TreeLeaf" that extend it. A branch has a boolean that validates it and 2 treemembers (one for success, one for failure). The leafs just have a void to execute. This allows me to prevent having to double check conditions in any tasks and gives a lot of freedom for structuring it. E.g. I made a tutorial island script where onLoop() checks what Instructor I am on and then progresses down a tree specfic to that instructor.

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