Jump to content

Not sure why my script isn't running


kingbutton

Recommended Posts

6 hours ago, dreameo said:

 

This comes from Oracles code convention.

 

Not sure what you're saying at the end lol.

Oracles naming conventions say that constants should be caps and underscores, but 'constant' is not synonymous with the final keyword. For example, the final keyword can be assigned to variables which may not have the same value between separate instances of a program. Consider the class below:

public class Demo {

  private final String someString;

  public Demo(String string) {
      someString = string;
  }
  
  public String getString() {
    return someString;
  }
  
}

The class can be used as follows:

System.out.println(new Demo("Hello").getString());
//> Hello
System.out.println(new Demo("abcdefg").getString());
//> abcdefg

You will notice that, although the variable 'someString' is final, its value is not the same in the example above (when two separate instances of the Demo class are created) and thus is not globally constant, hence a CAPS_AND_UNDERSCORES variable name is not appropriate. In the next example however, it would be:

public class DemoTwo {

  private final String SOME_STRING = "I'm constant!";

  public Demo() {}
  
  public String getString() {
    return SOME_STRING;
  }
  
}

Using it:

System.out.println(new DemoTwo().getString());
//> "I'm constant!"

I hope that makes sense and you now understand what I was previously trying to say and why I think that the final keyword does not always mean caps and underscores should be used for naming!

Apa

Edited by Apaec
Link to comment
Share on other sites

On 8/2/2017 at 3:12 PM, Imateamcape said:

no calls to methods inherited from Script are allowed before onLoop().

This means you can't call myPlayer() or npcs.closest()

Okay, So I learned that myPlayer(), NPCS, and RS2Objects need to be in the method to be able to use them.

But what If I have multiple methods that need to call them, do I just declare it multiple times?

Cause I'm trying to make a inventory check method, ( btw I got the script to run ) .

Where it checks if my inventory has a net or not, if it doesn't it goes bank and grabs one.

But I also have a method where when my inventory is full it goes bank and such.

So do I have to declare it twice cause that doesn't make sense to me.

Link to comment
Share on other sites

public boolean hasItem(String itemName){
	return getInventory.contains(itemName);
}

You just create methods to reduce any duplicate code. Example: I can call this method whenver i need to see if i have I have an item in my inventory.

For more practical use, the methods you invoke will have larger pieces of code inside them. 

Edited by dreameo
Link to comment
Share on other sites

2 hours ago, dreameo said:

public boolean hasItem(String itemName){
	return getInventory.contains(itemName);
}

You just create methods to reduce any duplicate code. Example: I can call this method whenver i need to see if i have I have an item in my inventory.

For more practical use, the methods you invoke will have larger pieces of code inside them. 

:???::???:

The method is already created. Why would you remake it? Also, getInventory isn't a field, it's a method

Edited by Imateamcape
Link to comment
Share on other sites

Well to anybody interested!

I figured out how to use methods, not sure if they're used efficiently though or if i can clean anything up, do more checks, iono.

But I GOT IT WORKING AND THAT'S WHAT MATTERS, also decided to change it to a barb fisher.

https://paste.ofcode.org/W8ezZaeTJckFcUx5MzYAVr

If anybody has some constructive criticism, besides my really simple question. Toss em here! 

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