I cant acess my variables

Discussion in 'Plugin Development' started by PizzaPixel, Mar 23, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    PizzaPixel

    I cant acess my variables after i do }
    My Variable are in my OnEnable here they are
    HTML:
    public void onEnable() {
            getServer().getPluginManager().registerEvents(this, this);
           
            ScoreboardManager sbManager = Bukkit.getScoreboardManager();
            Scoreboard sBoard = sbManager.getNewScoreboard();
           
            Team Red = sBoard.registerNewTeam("Red");
            Team Blue = sBoard.registerNewTeam("Blue");
            Team Yellow = sBoard.registerNewTeam("Yellow");
            Team Green = sBoard.registerNewTeam("Green");
    :'(I need help:'(

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  2. Offline

    MRPS

    Are you serious?

    Your variables in onEnable() are declared locally, so they can only be used in onEnable(). Move them above your onEnable(), in the class body, and change them to public, not private.
     
    Mattkx4 likes this.
  3. Offline

    Mattkx4



    What MRPS means:

    You need to move your variables outside the onEnable() method! Always remember that variables declared inside a method cannot be accessed anywhere, but inside that method!

    You need to declare your variables outside of your onEnable() like this:


    Code:java
    1. public class MyPlugin extends JavaPlugin {
    2. public <VariableType> <VariableName>;
    3.  
    4. public void onEnable() {
    5. // onEnable() code here
    6. }
    7. }


    Hope I helped :)
     
    MRPS likes this.
  4. Offline

    PizzaPixel

  5. Offline

    MRPS

    • Unacceptable behavior.
    PizzaPixel

    Learn basic java. You should know the difference between a fucking local variable and a field before making plugins.
     
  6. Offline

    Mattkx4

    MRPS
    When I first started out writing Java I didn't know what the difference was. I went to a forum and they told me NICELY. I'm sure everyone on this forums appreciates your knowledge, but people would thank you a lot more if you presented it in a nicer manner. They come here for questions and advice, not people cussing at them. If you want to tell them to learn Java, point them to a source where they can easily learn it....
     
    d3v1n302418 likes this.
  7. Offline

    MRPS


    If i've said it once, i've said it a thousand times:

    You should not be making Bukkit plugins without knowing basic java. Make some math formulas, make something that does things with arrays, learn datatypes, learn how to operate variables, learn the mechanics (the difference between private, public, protected, static, abstract, final, etc.). When you know that stuff, then come make plugins all you like. Half of this Plugin Development forum is filled with questions by people who barely know what a String array is let alone know what class inheritance is.

    Half of the issues posted to this forum section could be resolved if people learned java first.
     
    Venexor and Mattkx4 like this.
  8. Offline

    Mattkx4

    Very true, and I've heard it many, many times from you ;) but just don't use profanity.... And you're one of those special folks who somehow transfer there attitude to text....
     
  9. Offline

    MRPS


    I woke up yesterday in a great mood - it was spring break. After answering Plugin Development questions for close to 8 hours, I wanted to put a bullet in my brain. People need to learn basic java before they make plugins - it would save nice people like me so much time and effort.
     
  10. Offline

    Mattkx4

    MRPS
    lol. I totally agree.....
    Well I hope tomorrow is better :p
     
Thread Status:
Not open for further replies.

Share This Page