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

How do you store information temporarily without the use of an config?

Comments in 'Plugin Development' started by Legomite, May 6, 2014.

  1. Legomite
    Offline

    Legomite Active Member Plugin Developer

    Joined:
    Sep 8, 2013
    Posts:
    470
    Plugins:
    2
    Minecraft User:
    Legomite
    How do you store information temporarily without the use of an config? Do you have to use a private?
    Ex:
    PHP:
    Private $example false;
    When you change it with something like umm,
    PHP:
    $this->example true;
    Will this work also?
    PHP:
    Private $example 0;
    When you change it with something like umm,
    PHP:
    $this->example 1;
    //and will this work also?
    $this->example 0; + $a;
    $a 1;
  2. Falk
    Offline

    Falk Staff Member Global Moderator

    Joined:
    Sep 2, 2013
    Posts:
    1,707
    Plugins:
    22
    Minecraft User:
    Falkirknh
    private means the variable can't be retrieved from outside it's class, public means it could be.
  3. Legomite
    Offline

    Legomite Active Member Plugin Developer

    Joined:
    Sep 8, 2013
    Posts:
    470
    Plugins:
    2
    Minecraft User:
    Legomite
    S
    So I have to change it to public?
  4. Falk
    Offline

    Falk Staff Member Global Moderator

    Joined:
    Sep 2, 2013
    Posts:
    1,707
    Plugins:
    22
    Minecraft User:
    Falkirknh
    No, either is fine.
  5. Legomite
    Offline

    Legomite Active Member Plugin Developer

    Joined:
    Sep 8, 2013
    Posts:
    470
    Plugins:
    2
    Minecraft User:
    Legomite
    Wait so my question is right?
  6. BlinkSun
    Offline

    BlinkSun Active Member Plugin Developer

    Joined:
    Mar 26, 2014
    Posts:
    128
    Plugins:
    4
    Minecraft User:
    BlinkSun
    @Legomite if you want to use a variable in any function of your plugin, you need to declare it
    at the begining of the plugin, with the private $api;

    PHP:
    class PLUGIN implements Plugin
    {
        private 
    $api;
        private 
    $exemple;

        public function 
    __construct(ServerAPI $api$server false)
        {
            
    $this->api $api;
            
    $this->exemple = array();
        }
    ...
    you can easy store informations in $exemple but this variable ll be deleted if you stop de server.
    dont forget to unset() if it contain useless value !
  7. Legomite
    Offline

    Legomite Active Member Plugin Developer

    Joined:
    Sep 8, 2013
    Posts:
    470
    Plugins:
    2
    Minecraft User:
    Legomite
    That's what I want it to do :)
  8. Beast Mode
    Offline

    Beast Mode Banned

    Joined:
    Apr 4, 2014
    Posts:
    16
    PHP:
    public function UnsetArray($data){
        if(
    $key in_array("$data"$this->example)){
            unset(
    $this->example[$key]);
        }
    }
    ^^^^^ This will let you unset arrays

    PHP:
    public function SetArray($data){
        
    array_push($this->example"$data");
    }
    ^^^^^ This will let you set arrays

    PHP:
    public function CreateArray($data){
        
    $this->example = array();
    }
    ^^^^^ This will let you create arrays @Legomite
    Last edited: May 9, 2014
  9. Tuff
    Offline

    Tuff Active Member

    Joined:
    Jan 25, 2014
    Posts:
    203
    Minecraft User:
    Roboroug2
    Wow! this would have been really helpful, I had no idea you could do the public variable thing, I made a CTF plugin and I used the config to link all the functions together this is ridiculously helpful thanks.
    iJoshuaHD and Falk like this.

Share This Page

Advertisement