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

Code not working

Discussion in 'Facepalm' started by Kabluinc, Dec 30, 2016.

  1. Kabluinc

    Kabluinc Baby Zombie

    Messages:
    129
    I'm trying to get the players in a level and send them a message usng this code:

    PHP:
        $winner $sender->getServer()->getLevelByName("world")->getPlayers();
                
    $winner->sendMessage("you won!");
    in console its saying
    [13:15:32] [Server thread/CRITICAL]: Error: "Call to a member function sendMessage() on array" (EXCEPTION)

    please help
     
  2. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    try
    PHP:
    foreach ($sender->getServer()->getLevelByName("world")->getPlayers() as $winner$winner->sendMessage("you won!");
     
    Sandertv and Primus like this.
  3. Kabluinc

    Kabluinc Baby Zombie

    Messages:
    129
    Perfect thanks
     
  4. Awzaw

    Awzaw Zombie Pigman Poggit Admin

    Messages:
    726
    GitHub:
    awzaw
    for anyone who wonders why... getPlayers() returns an array of Player objects, not a single Player object.
     
  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.