Variable from Main Class

Discussion in 'Plugin Development' started by MasterDoctor, Jan 4, 2016.

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

    MasterDoctor

    Hi, I'm unable to access a variable from the Main Class, in my Command class. I thought about getters and setters but I couldn't work out how you were meant to access the getters accessed setters from another class.

    Halppp!!
     
  2. Offline

    Zombie_Striker

    @MasterDoctor
    You have to get the instance of the main class:
    Code:
    public Main mainclass instance;// the instance
    
    public Constuctor4TheClass(Main The passed instance){//the constructor for the class
    Mainclass Instance = the passed instance//passing the instance
    }
    
    Mainclass Instance.getOBJECT();//getting the Getter
     
  3. Offline

    MasterDoctor

    So I just use a constructor to get the the instance? Your code doesn't come up very clear, I don't know if it's my tablet.


    What goes where mainclass is? And is that line (the instance) in the Main or command class?
     
  4. Offline

    teej107

    No, his code is actually kind of messy to read. Do you know what a constructor is? You should because it's basic Java.
     
  5. Offline

    MasterDoctor

    I do know what a constructor is, I just got confused by his code
     
  6. Offline

    teej107

    @MasterDoctor so you have 2 options, both of them require passing an Object through the parameters of the constructor.

    1. Pass the object you need
    2. Create a getter in your JavaPlugin class. Pass the JavaPlugin object.
     
  7. Offline

    MasterDoctor

    How exactly do I pass the object? I've only ever passed the JavaPlugin class
     
    Last edited: Jan 4, 2016
  8. Offline

    teej107

    Through the parameters :p
     
    Zombie_Striker likes this.
  9. Offline

    Zombie_Striker

    MasterDoctor likes this.
  10. Offline

    teej107

    MasterDoctor likes this.
  11. Offline

    MasterDoctor

  12. Offline

    mythbusterma

    @MasterDoctor

    It's simple Java, and yes you can use it. Create a getter.
     
    Zombie_Striker and timtower like this.
  13. Offline

    MasterDoctor

    But then it's still the same problem...
     
  14. Offline

    Zombie_Striker

    • Create the main class.
    • Then create the Command class, and passes the main class instance to that class
    • Then create the other class that needs Command class instance, and pass the Command class instance.
     
  15. Offline

    MasterDoctor

    Umm ok
     
Thread Status:
Not open for further replies.

Share This Page