Jump to content
View in the app

A better way to browse. Learn more.

OSBot :: 2007 OSRS Botting

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Enum with Switch troubles

Featured Replies

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);
    }
   

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

  • Author
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

Create an account or sign in to comment

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.