Jump to content

Enum with Switch troubles


evert123

Recommended Posts

Hello guys, I read Apaec's guide: "A beginners guide to writing OSbot scripts" and got excited to use enum with switch.
So I'm exploring this method but get weird results, I will try to explain as clearly as I can.

What (I think) my script is supposed to be doing right now:

  1. Check if within the area
  2. If not walk to sellpoint, send message "walking back"
  3. Check if more than 1 law rune in inventory
  4. If true send message "test"

What is happening when the script is run:

  1. When my player is in the area it spams "walkinig back" but is not walking back
  2. When my player is NOT in the area it walks back and is not spamming "walking back"

  

 

 

    private final
    Area lumbyBank = new Area(3207, 3217, 3210, 3220);
    Position sellPoint = new Position (3208, 3217, 2);
   

    private enum State {
        WALK, TRADE, EXIT
    }

private State getState() {
        if (!lumbyBank.contains(myPosition()))
                return State.WALK;      
        if (getInventory().getItem("Law rune").getAmount() >= 1)
                return State.TRADE;
        return State.EXIT; 
    }
    
    @Override
    public int onLoop() throws InterruptedException {
        switch (getState()) {
        case WALK:
                getWalking().walk(sellPoint);
                log("walk back");
            break;
        case TRADE:
            log("test");
            break;
        case EXIT:
            stop();
            break;
        }    
        
        return random(200, 300);
    }
   

Link to comment
Share on other sites

5 minutes ago, evert123 said:

Hello guys, I read Apaec's guide: "A beginners guide to writing OSbot scripts" and got excited to use enum with switch.
So I'm exploring this method but get weird results, I will try to explain as clearly as I can.

What (I think) my script is supposed to be doing right now:

  1. Check if within the area
  2. If not walk to sellpoint, send message "walking back"
  3. Check if more than 1 law rune in inventory
  4. If true send message "test"

What is happening when the script is run:

  1. When my player is in the area it spams "walkinig back" but is not walking back
  2. When my player is NOT in the area it walks back and is not spamming "walking back"

  

 

 

    private final
    Area lumbyBank = new Area(3207, 3217, 3210, 3220);
    Position sellPoint = new Position (3208, 3217, 2);
   

    private enum State {
        WALK, TRADE, EXIT
    }

private State getState() {
        if (!lumbyBank.contains(myPosition()))
                return State.WALK;      
        if (getInventory().getItem("Law rune").getAmount() >= 1)
                return State.TRADE;
        return State.EXIT; 
    }
    
    @Override
    public int onLoop() throws InterruptedException {
        switch (getState()) {
        case WALK:
                getWalking().walk(sellPoint);
                log("walk back");
            break;
        case TRADE:
            log("test");
            break;
        case EXIT:
            stop();
            break;
        }    
        
        return random(200, 300);
    }
   

 

Firstly your Lumbridge bank area is incorrect, I would recommend you use the constant Banks.LUMBRIDGE_UPPER instead.

Secondly your logic in general seems weird. I would recommend not using the state pattern because it just confuses things.

 

Edited by Explv
Link to comment
Share on other sites

5 minutes ago, Explv said:

 

Firstly your Lumbridge bank area is incorrect, I would recommend you use the constant Banks.LUMBRIDGE_UPPER instead.

Secondly your logic in general seems weird. I would recommend not using the state pattern because it just confuses things.

 

Thank you very much, nice response time to :)

I will try a different method and do some figuring out myself

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