Jump to content

Shortening code


Rumple

Recommended Posts

Google State Machine, it's basically the foundation for most scripts. Your onLoop will only run a function. States can be stored in your main file, or you can create a class. Actually, you could even create a class for each state. The point is, it allows you to break up your code into smaller, more defined sections. here's the logic behind it. 

1*z-cGUTYS40cSjcMWgiOLww.png

Code length does not define proper or improper. Being able to catch and contain errors using a state machine, will not only make your life easier, but will allow you to be much more diverse with your code. A state is essentially a "condition" which defines everything, so by using states, you can be much more diverse in your approach. 


 

Edited by redeems
Link to comment
Share on other sites

I'm still getting used to using a function like this, but I think this may work. If you have a  bunch of repetitive actions with only minor differences, you can build a function like this and plug in specifiers. In this case your position, the object, and the interaction associated with it. If it doesn't work (haven't tested, and still getting use to using these myself) you can mess around with it.

Someone feel free to correct me if theres something wrong/better

// How you would use it
clickThisShit(Position,Object,"Action")

// The one line can replace a block of the repetetive chuncks


//Make a function like this in your script

private void clickThisShit(Position position, RS2Object object, String action) {

        if (position.equals(myPosition())) {

            if (!object.isVisible())
                getCamera().toEntity(object);

            if (object != null && object.isVisible() && object.hasAction(action)) {
                object.interact(action);

                new ConditionalSleep(10000, 250){
                    @Override
                    public boolean condition() throws InterruptedException{
                        return (!myPlayer().isMoving() && !myPlayer().isAnimating());
                    }
                }.sleep();
            }
        }
    }

 

Edited by Dab in a Lab
  • Like 1
Link to comment
Share on other sites

On 3/13/2019 at 12:04 AM, Dab in a Lab said:

I'm still getting used to using a function like this, but I think this may work. If you have a  bunch of repetitive actions with only minor differences, you can build a function like this and plug in specifiers. In this case your position, the object, and the interaction associated with it. If it doesn't work (haven't tested, and still getting use to using these myself) you can mess around with it.

Someone feel free to correct me if theres something wrong/better


// How you would use it
clickThisShit(Position,Object,"Action")

// The one line can replace a block of the repetetive chuncks


//Make a function like this in your script

private void clickThisShit(Position position, RS2Object object, String action) {

        if (position.equals(myPosition())) {

            if (!object.isVisible())
                getCamera().toEntity(object);

            if (object != null && object.isVisible() && object.hasAction(action)) {
                object.interact(action);

                new ConditionalSleep(10000, 250){
                    @Override
                    public boolean condition() throws InterruptedException{
                        return (!myPlayer().isMoving() && !myPlayer().isAnimating());
                    }
                }.sleep();
            }
        }
    }

 

Thats the thing is that there are 2 objects that dont have "actions" or "names" available only "Object ID" and thus the script will not click on them the way i need in-order to continue or not fall off ledge. 

 

This is not a simple agility script. I have made a simple agility script that collects marks. 

Link to comment
Share on other sites

Well I was just showing you how to shorten your code a bit

But you could probably grab the object ID when its visible/your next object you need to interact with and do object.interact();   and not put in a string, so it will just click that object regardless of what action is has, or if it even has an action

Edited by Dab in a Lab
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...