Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How to get data from config?

Comments in 'Plugin Development' started by iiDeathStrokeii, Jun 4, 2015.

  1. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    $stats is a local variable.
    $this->stats is a class property.
    This is PHP, not Java.
    Andrey Nazarchuk likes this.
  2. Andrey Nazarchuk
    Offline

    Andrey Nazarchuk Active Member

    Joined:
    Dec 30, 2013
    Posts:
    332
    Minecraft User:
    digita1eclipse
    I dont understand.
    Does that mean I should use $stats->get?
    Because I need to use $this or else they will get the same one?
    I am confusing myself now...
    Well thanks for the help.
  3. Andrey Nazarchuk
    Offline

    Andrey Nazarchuk Active Member

    Joined:
    Dec 30, 2013
    Posts:
    332
    Minecraft User:
    digita1eclipse
    Ok it still says its undefined...
    I even tried getting the config with $this->stats->get and it still says undefined.
  4. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    No. To make it save over functions, use $this->stats.

    And it would be a good practice to define `private $stats;` at the beginning of your class too, although it is not needed.
  5. Andrey Nazarchuk
    Offline

    Andrey Nazarchuk Active Member

    Joined:
    Dec 30, 2013
    Posts:
    332
    Minecraft User:
    digita1eclipse
    Oh! So got get something I just have to to $this->stats("deaths"); ? But how do it set or save it then?
    I can't define it, stats is defined in on enable, I just need to be able to get, set, and save to it.
  6. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    No. Just simply use $this->stats instead of $stats.
  7. Andrey Nazarchuk
    Offline

    Andrey Nazarchuk Active Member

    Joined:
    Dec 30, 2013
    Posts:
    332
    Minecraft User:
    digita1eclipse
    When defining or using it?
  8. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    I'd you define it as $stats, use it as $stats.
    If you define it as $this->stats, use it as $this->stats.
    But $stats is a function-local variable. It won't save over functions. So use $this->stats instead.
  9. Andrey Nazarchuk
    Offline

    Andrey Nazarchuk Active Member

    Joined:
    Dec 30, 2013
    Posts:
    332
    Minecraft User:
    digita1eclipse
    Alright thank you for a clean and easy to understand reply. :D
    It no longer crashes, but it does not work which is worse than crashing because now I don't know the problem.

Share This Page

Advertisement