Jump to content

Does this code make sense/will it work in the long run?


Lol_marcus

Recommended Posts

So I did some quick reading, but I still don't quite understand what the lack of the "@Override" handler for the 2nd and 3rd onLoops will do to my script, if anything at all?

I'm using a simple drop down menu for the options. I've run to all banks and it works fine.

When I ask if it'll work in the long run is, if I have a script that loops. Like a WCing script. If I give it the option to cut willows, and the other oaks, will it keep running fine without the Override?

package core;

import javax.swing.JOptionPane;

import org.osbot.rs07.api.map.constants.Banks;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;


@ScriptManifest(name = "Bank Walker", version = 1, author = "Marcus", logo = "", info = "Walks and runs to banks")


public class Main extends Script {
	
    @Override
    public void onStart() throws InterruptedException {

    	String userOptions[] = {"Varrock", "Falador", "Edgeville"};
		String userChoice = ""+(String)JOptionPane.showInputDialog(null, "Choose a location", "Bank Walker", JOptionPane.PLAIN_MESSAGE, null, userOptions, userOptions[1]);
    
    	if(userChoice.equals("Varrock")) {
    		onLoop();
    	} else if (userChoice.equals("Falador")) {
    		onLoop2();
    	} else if (userChoice.equals("Edgeville")) {
    		onLoop3();
    	} else {
    		stop(false);
    	}    
    }
    
    @Override
    public int onLoop() throws InterruptedException {

        if (Banks.GRAND_EXCHANGE.contains(myPosition())) {
        	stop(false);
        } else {
        	combat.toggleAutoRetaliate(false);
            getWalking().webWalk(Banks.GRAND_EXCHANGE);
        }
        return 700;
    }

public int onLoop2() throws InterruptedException {

    if (Banks.FALADOR_WEST.contains(myPosition())) {
    	stop(false);
    } else {
    	combat.toggleAutoRetaliate(false);
        getWalking().webWalk(Banks.FALADOR_WEST);
    }
    return 700;
}

public int onLoop3() throws InterruptedException {

    if (Banks.EDGEVILLE.contains(myPosition())) {
    	stop(false);
    } else {
    	combat.toggleAutoRetaliate(false);
        getWalking().webWalk(Banks.EDGEVILLE);
    }
    return 700;
}
}

 

Link to comment
Share on other sites

I think something like this is more what you're looking for

package core;

import javax.swing.JOptionPane;

import org.osbot.rs07.api.map.constants.Banks;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;


@ScriptManifest(name = "Bank Walker", version = 1, author = "Marcus", logo = "", info = "Walks and runs to banks")


public class Main extends Script {

    int task;

    @Override
    public void onStart() throws InterruptedException {

        String userOptions[] = {"Varrock", "Falador", "Edgeville"};
        String userChoice = ""+(String)JOptionPane.showInputDialog(null, "Choose a location", "Bank Walker", JOptionPane.PLAIN_MESSAGE, null, userOptions, userOptions[1]);

        if(userChoice.equals("Varrock")) {
            task = 1;
        } else if (userChoice.equals("Falador")) {
            task = 2;
        } else if (userChoice.equals("Edgeville")) {
            task = 3;
        } else {
            stop(false);
        }
    }
    
    @Override
    public int onLoop() throws InterruptedException {
        switch (task) {
            case 1:
                return taskOne();
            case 2:
                return taskTwo();
            case 3:
                return taskThree();
        }
        return 700;
    }

    public int taskOne() throws InterruptedException {

        if (Banks.GRAND_EXCHANGE.contains(myPosition())) {
            stop(false);
        } else {
            combat.toggleAutoRetaliate(false);
            getWalking().webWalk(Banks.GRAND_EXCHANGE);
        }
        return 700;
    }

    public int taskTwo() throws InterruptedException {

        if (Banks.FALADOR_WEST.contains(myPosition())) {
            stop(false);
        } else {
            combat.toggleAutoRetaliate(false);
            getWalking().webWalk(Banks.FALADOR_WEST);
        }
        return 700;
    }

    public int taskThree() throws InterruptedException {

        if (Banks.EDGEVILLE.contains(myPosition())) {
            stop(false);
        } else {
            combat.toggleAutoRetaliate(false);
            getWalking().webWalk(Banks.EDGEVILLE);
        }
        return 700;
    }
}
  • Like 1
Link to comment
Share on other sites

Area bank;
@Override
    public void onStart() throws InterruptedException {

        String userOptions[] = {"Varrock", "Falador", "Edgeville"};
        String userChoice = ""+(String)JOptionPane.showInputDialog(null, "Choose a location", "Bank Walker", JOptionPane.PLAIN_MESSAGE, null, userOptions, userOptions[1]);

    switch(userChoice) {
       case "Varrock":
                bank = Banks.FALADOR_WEST;
        break;
           case "Falador":
                bank = Banks.FALADOR_WEST;
        break;
           case 
        "Edgeville":
                bank = Banks.GRAND_EXCHANGE;
        break;
    }
    combat.toggleAutoRetaliate(false);
    }
    
    @Override
    public int onLoop() throws InterruptedException {
       if (bank.contains(myPosition())) {
            stop(false);
        } else {
            getWalking().webWalk(bank);
        }
        return 700;
    }

 

this probaly has somemistake but just did a quick edit in notepad lol

Edited by TheMcPker
Link to comment
Share on other sites

28 minutes ago, Camaro said:

I think something like this is more what you're looking for


package core;

import javax.swing.JOptionPane;

import org.osbot.rs07.api.map.constants.Banks;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;


@ScriptManifest(name = "Bank Walker", version = 1, author = "Marcus", logo = "", info = "Walks and runs to banks")


public class Main extends Script {

    int task;

    @Override
    public void onStart() throws InterruptedException {

        String userOptions[] = {"Varrock", "Falador", "Edgeville"};
        String userChoice = ""+(String)JOptionPane.showInputDialog(null, "Choose a location", "Bank Walker", JOptionPane.PLAIN_MESSAGE, null, userOptions, userOptions[1]);

        if(userChoice.equals("Varrock")) {
            task = 1;
        } else if (userChoice.equals("Falador")) {
            task = 2;
        } else if (userChoice.equals("Edgeville")) {
            task = 3;
        } else {
            stop(false);
        }
    }
    
    @Override
    public int onLoop() throws InterruptedException {
        switch (task) {
            case 1:
                return taskOne();
            case 2:
                return taskTwo();
            case 3:
                return taskThree();
        }
        return 700;
    }

    public int taskOne() throws InterruptedException {

        if (Banks.GRAND_EXCHANGE.contains(myPosition())) {
            stop(false);
        } else {
            combat.toggleAutoRetaliate(false);
            getWalking().webWalk(Banks.GRAND_EXCHANGE);
        }
        return 700;
    }

    public int taskTwo() throws InterruptedException {

        if (Banks.FALADOR_WEST.contains(myPosition())) {
            stop(false);
        } else {
            combat.toggleAutoRetaliate(false);
            getWalking().webWalk(Banks.FALADOR_WEST);
        }
        return 700;
    }

    public int taskThree() throws InterruptedException {

        if (Banks.EDGEVILLE.contains(myPosition())) {
            stop(false);
        } else {
            combat.toggleAutoRetaliate(false);
            getWalking().webWalk(Banks.EDGEVILLE);
        }
        return 700;
    }
}

how did you get scripter 2 rank? they aren't even diffrent tasks. so the name task makes no sence. or the way that its done

Link to comment
Share on other sites

1 minute ago, TheMcPker said:

how did you get scripter 2 rank? they aren't even diffrent tasks. so the name task makes no sence. or the way that its done

the 'Task' represent the only task that will be performed throughout the entirety of the script, which is chosen by the dialog that shows at the beginning of the script. Also, they are different tasks. Each function webwalks to a different bank. What are you on about?

Link to comment
Share on other sites

Just now, Camaro said:

the 'Task' represent the only task that will be performed throughout the entirety of the script, which is chosen by the dialog that shows at the beginning of the script. Also, they are different tasks. Each function webwalks to a different bank. What are you on about?

Every "task" is the exact same code using a diffrent varible area so no its just  walk to bank with only diffrence being the bank that you'd be walking to to call it a task would be correct but no its not diffrent tasks

Link to comment
Share on other sites

11 minutes ago, TheMcPker said:

Every "task" is the exact same code using a diffrent varible area so no its just  walk to bank with only diffrence being the bank that you'd be walking to to call it a task would be correct but no its not diffrent tasks

I hope you realize I only slightly edited his code so it would actually work

Link to comment
Share on other sites

1 minute ago, Camaro said:

I hope you realize I only slightly edited his code so it would actually work

than why are you defending for your choice of code? instead of just saying that you just did a quick edit also im pretty sure the code you edited took more time than doing it proppery it was just a quick delete of 3 methods + change of varible and then a switch statement instead of the if else code you already made a switch statement even. tl:dr don't defend your code when its bad and just say it was a quick edit. 

Link to comment
Share on other sites

Just now, TheMcPker said:

than why are you defending for your choice of code? instead of just saying that you just did a quick edit also im pretty sure the code you edited took more time than doing it proppery it was just a quick delete of 3 methods + change of varible and then a switch statement instead of the if else code you already made a switch statement even. tl:dr don't defend your code when its bad and just say it was a quick edit. 

Pretty sure hes wondering more about how tasks work in general, which your answer fails to do

Link to comment
Share on other sites

4 minutes ago, Camaro said:

Pretty sure hes wondering more about how tasks work in general, which your answer fails to do

you are showing how tasks works in probaly the worst ways possible you are correct in using a switch statement but atleast if your goal truly is to help understand how tasks work than type a quick wcing script example takes 2-3 mins at max and show how to build that properly instead of using 3 identical methods as completly diffrent tasks as a example of how tasks works.. show how to progress between tasks ect you just showed a new scripter that its okay to not use methods propperly great job.

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