Jump to content

Pass Area variable to method


bumzag

Recommended Posts

I apologize for asking another question so quickly.

I want to create a reusable method for webwalking so I don't have to keep typing it out. Basically I want to do this:

 

private void walk() {

             if (!x.contains(myPosition())) {
            getWalking().webWalk(x);
            Sleep.sleepUntil(() -> x.contains(myPosition()), 2000);
            sleep(random(100, 500));
}

And I want to be able to call the method by doing

walk(x);

Somewhere in the script. So that I could change x to a different area, like "walk(cowArea);" or "walk(giantArea);" whenever I need. I know this is easy but it's kicking my ass.

Link to comment
Share on other sites

6 minutes ago, bumzag said:

I apologize for asking another question so quickly.

I want to create a reusable method for webwalking so I don't have to keep typing it out. Basically I want to do this:

 

private void walk() {

             if (!x.contains(myPosition())) {
            getWalking().webWalk(x);
            Sleep.sleepUntil(() -> x.contains(myPosition()), 2000);
            sleep(random(100, 500));
}

And I want to be able to call the method by doing

walk(x);

Somewhere in the script. So that I could change x to a different area, like "walk(cowArea);" or "walk(giantArea);" whenever I need. I know this is easy but it's kicking my ass.

No need to worry about asking too many questions. That's how you learn 🙂 

You are just missing the parameter for the method. A parameter is placed in between the parenthesis after your method name, so it would look like this walk(Area x)

In code. Also you don't need to use a sleep as the WebWalker will pause further execution of the script until the event is over.

private void walk(Area x) {
    if (!x.contains(myPosition())){
        getWalking().webWalk(x);
    }
}
Link to comment
Share on other sites

6 minutes ago, BravoTaco said:

No need to worry about asking too many questions. That's how you learn 🙂 

You are just missing the parameter for the method. A parameter is placed in between the parenthesis after your method name, so it would look like this walk(Area x)

In code. Also you don't need to use a sleep as the WebWalker will pause further execution of the script until the event is over.


private void walk(Area x) {
    if (!x.contains(myPosition())){
        getWalking().webWalk(x);
    }
}

Awesome thanks man, that works. I had it set up like that but I didn't know the x was interchangeable. The x is just a placeholder and can be changed out with anything right?  Like I could do 

private void walk(Area flippityFloppityFloomSham) {

    if(!flippityFloppityFloomSham.contains(myPositions())){

        getWalking().webWalk(flippityFloppityFloomSham);

    }

}

 

And it would work the same, right? Thanks again

Link to comment
Share on other sites

4 minutes ago, bumzag said:

Awesome thanks man, that works. I had it set up like that but I didn't know the x was interchangeable. The x is just a placeholder and can be changed out with anything right?  Like I could do 

private void walk(Area flippityFloppityFloomSham) {

    if(!flippityFloppityFloomSham.contains(myPositions())){

        getWalking().webWalk(flippityFloppityFloomSham);

    }

}

 

And it would work the same, right? Thanks again

Yeah exactly, the parameter name does not matter. Only the type, in this case Area, does.

Edited by BravoTaco
Link to comment
Share on other sites

I'm glad to see that @BravoTaco could help you out.

However, I would like to point out that it is highly advised to first learn the fundamentals of Java and OOP (Object-oriented programming) before diving into developing scripts. 

Although you're always free to ask questions, a question is never 'dumb', it is obvious that you do not master the fundamentals and that you'll make it a lot harder for yourself by not properly learning fundamentals in the beginning.

  • Like 2
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...