[SIMPLE] Public static boolean help

Discussion in 'Plugin Development' started by Unscrewed, May 2, 2011.

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

    Unscrewed

    Hey there!
    I added this in the main class of my plugin:

    Code:
    public static boolean test = false;
    When I make another class and type this:

    Code:
     public class Police extends PlayerListener {
    	{
    if(!test)
    {
        test = true;
    } else
    {
        test = false;
    }
    return test;
    }
    }
    It doesn't recognize "test".
    Please help me with this?

    Please help me, with this I can go further with my plugin. :)

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 14, 2016
  2. Hello again :p

    You have to reference to the class that the public variable is in.

    So in your police class


    Code:
     public class Police extends PlayerListener {
    private final Mainclass reference = new Mainclass(this);
        {
    if(!reference.test)
    {
        reference.test = true;
    } else
    {
        reference.test = false;
    }
    return reference.test;
    }
    }
    Then in your main class don't forget to add
    Code:
    public static mainclassname mainref;
    
    public MainClassName(Police instance) {
            mainref = instance;
        }
     
  3. Offline

    nickguletskii

    @Adamki11s

    Well, it is static, so you don't need an instance.
    So you should reference like this:
    Code:
    NameOfTheClassThatContainsTheVariable.test
     
  4. Offline

    Unscrewed

    Thanks! :D:D

    && Thanks to you too! :D:D

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 14, 2016
  5. Forgot about that :p
     
Thread Status:
Not open for further replies.

Share This Page