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

Global Variable

Comments in 'Plugin Development' started by CrazedMiner, Jun 6, 2015.

  1. CrazedMiner
    Offline

    CrazedMiner Notable Member Plugin Developer

    Joined:
    Jan 31, 2015
    Posts:
    348
    Plugins:
    2
    Minecraft User:
    CrazedMinerYT
    In my Main.php I want to have $seconds = 0; and then from my seconds.php file be able to get this variable and add 1 to $seconds ($seconds++;), I cant figure out how to do this so any and all help is appreciated! :)
  2. luca28pet
    Offline

    luca28pet Active Member

    Joined:
    Feb 20, 2014
    Posts:
    251
    Minecraft User:
    luca28pet
    Main class
    PHP:
    class SomeClass extends PluginBase{
      public 
    $seconds 0;
      public function 
    onEnable(){
        
    $this->getServer()->getScheduler()->scheduleRepeatingTask(new Seconds($this), $this);
      }
    }
    Seconds.php:
    PHP:
    class Seconds extends PluginTask{
      public function 
    __construct($plugin){
      
    parent::__construct($plugin);
      
    $this->plugin $plugin;
      }

      public function 
    onRun($t){
        
    $this->plugin->seconds++;
      }
    }
    iksaku, EvolSoft and CrazedMiner like this.
  3. CrazedMiner
    Offline

    CrazedMiner Notable Member Plugin Developer

    Joined:
    Jan 31, 2015
    Posts:
    348
    Plugins:
    2
    Minecraft User:
    CrazedMinerYT
    Now I'm getting this error on the console :/
    Code:
    22:36:57 [NOTICE] ClassCastException: "Object of class CrazedMiner\Main could not be converted to int" (E_NOTICE) in "/src/pocketmine/scheduler/ServerScheduler" at line 120
    
    
  4. iksaku
    Offline

    iksaku Notable Member Plugin Developer

    Joined:
    Sep 2, 2013
    Posts:
    1,132
    Plugins:
    4
    Minecraft User:
    iksaku
    That¿s because you're doing something wrong in your code xD
  5. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Why not just use time()?
    CrazedMiner likes this.

Share This Page

Advertisement