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

Help with a defined variable claiming to be undefined

Comments in 'Plugin Development' started by args, Jun 15, 2014.

  1. args
    Offline

    args New Member

    Joined:
    Jun 14, 2014
    Posts:
    47
    Minecraft User:
    args
    Hey all,
    I'm working on my timer for the lobby in my plugin, And I'm getting an error with my variable claiming to be undefined when the plugin runs in PM,

    Code:
    <?php
    namespace EMC;
    use pocketmine\scheduler\PluginTask;
    use pocketmine\Server;
    class serverTimer extends PluginTask{
        public $lobbyTime = 61;
    
        public function onRun($currentTick){
            Server::getInstance()->broadcastMessage(">>The next game will begin in ".$this->lobbyTime." seconds");
    
            if($this->$lobbyTime == 60){
                $this->timerStartMessages();
    
            }
    
            if($this->$lobbyTime < 6 && $this->$lobbyTime>0){
                $this->timerStartMessages();
            }
    
            if($this->$lobbyTime = 0){
                $totalPlayers = 0;
    
                foreach($this->getOwner()->getServer()->getOnlinePlayers() as $p){
                    $totalPlayers++;
                }
                Server::getInstance()->broadcastMessage(">>Timer reset: ".$totalPlayers." online, 4 needed to play!");
    
                $this->$lobbyTime = 60;
    
            }
    
            $this->$lobbyTime--;
        }
    
        public function timerStartMessages(){
            Server::getInstance()->broadcastMessage(">>The next game will begin in ".$this->lobbyTime." seconds");
    
        }
    }
    
    
    The error starts at the line at the first line in the onRun(), claiming the variable "lobbyTime" is undefined.

    Earlier the plugin would allow me to run untill the "if" statement before it gave the error.
    Thanks for reading :)

    Ps: please forgive me if I've done something real stuipid without realising. I've had a massive crash course in php and am getting alright at a lot of things, but theres just minor things i still gotta learn. Also i looked online for anyone with similar issues, but I haven't found anything so far.
  2. blocksandgold
    Offline

    blocksandgold Active Member

    Joined:
    May 7, 2014
    Posts:
    68
    Minecraft User:
    bifag
    remove the $
    PEMapModder likes this.
  3. blocksandgold
    Offline

    blocksandgold Active Member

    Joined:
    May 7, 2014
    Posts:
    68
    Minecraft User:
    bifag
    $this->lobbyTime = 60;
    $this->lobbyTime--;
    swagboy47 likes this.
  4. args
    Offline

    args New Member

    Joined:
    Jun 14, 2014
    Posts:
    47
    Minecraft User:
    args
    thank you :)

Share This Page

Advertisement