1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Error getEntities

Discussion in 'Development' started by kaliiks, Feb 11, 2017.

  1. kaliiks

    kaliiks Zombie

    Messages:
    250
    PHP:
    class NPCTask extends Task
    {

        public function 
    __construct(Core $plugin)
        {
            
    $this->plugin $plugin;
            
    $this->text = new FloatingTextParticle(new Vector3(78310.7, -1199), """§e");
        }

        public function 
    onRun($currentTick)
        {
            
    $level $this->plugin->getServer()->getLevelByName("New spawn2");
            foreach (
    $level->getEntities() as $ent){
                if(
    $ent->getId() == 2){
                    
    $ent->setNameTag("§l§6MicroBattle§r\n  §7" count($this->plugin->getOnline(1)) . " Playing");
                }
            }
        }
    }
    error
    Code:
    Notice: Undefined variable: level in C:\Users\uzivatel\Desktop\Server\plugins\Core\src\Core\Core.php on line 1044
    [14:31:55] [Server thread/CRITICAL]: Could not execute task Core\NPCTask: Call to a member function getEntities() on unknown
    [14:31:55] [Server thread/CRITICAL]: Error: "Call to a member function getEntities() on unknown" (EXCEPTION) in "/Core/src/Core/Core" at line 1044
    DE]
     
  2. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
    Please include line numbers. And that code is some rather random snippet of a big plugin, so we can't magically know what your plugin does where and how. Please either post the full code, or large parts of it. We're not here to get thrown at with some random piece of code and an error message. Provide steps you've already taken (e.g. I've ensured that the level "New spawn2" exists, and the function returns a valid level object).
     
    corytortoise likes this.
  3. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    do a vardump on $level
    i think $level is null or not instance of Level
     
    Sandertv likes this.
  4. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
    It's definitely not null, because it says call on UNKNOWN. not call on null.
     
  5. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
     
  6. Awzaw

    Awzaw Zombie Pigman Poggit Admin

    Messages:
    726
    GitHub:
    awzaw
    robske_110 is spot on, you need to start using git/github: you'll get help faster and it will make coding a LOT easier for you in the long run. Also, it's a very bad idea to use spaces in world names.
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.