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

Solved Error with if

Discussion in 'Development' started by SkySeven, May 8, 2017.

  1. SkySeven

    SkySeven Baby Zombie

    Messages:
    145
    GitHub:
    SkySevenMC
    Hello,
    An if is not fonctional in this code :
    PHP:
    $cdn $this->arenas[$level][1]; //array

    if($cdn == 0){ //here

    $block $lvl->getBlockIdAt($player->x$player->y-0.1$player->z);
    if(
    $block == 355){
    if(
    $this->getTeam($player) == "blue"){

    }elseif(
    $this->getTeam($player) == "red"){

    }
    foreach(
    $lvl->getPlayers() as $pl){
    if(
    $this->getTeam($pl) == "blue"){
    $pl->teleport(new Position($config->get("spawnX-Blue"),$config->get("spawnY-Blue"),$config->get("spawnZ-Blue"),$this->getServer()->getLevelByName($config->get("Level"))));
    }
    if(
    $this->getTeam($pl) == "red"){
    $pl->teleport(new Position($config->get("spawnX-Red"),$config->get("spawnY-Red"),$config->get("spawnZ-Red"),$this->getServer()->getLevelByName($config->get("Level"))));
    }
    }
    $this->resetArena($arena $level);
    }
    }
    Help me please :)
    Thank you in advance !
     
  2. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    There is no way for us to determine the problem. Share any errors/output you might get, and explain what you expected to happen and what actually happened.
     
    Sandertv likes this.
  3. Lorak9904

    Lorak9904 Witch

    Messages:
    58
    Doesn't statements needs ,,return true" after all...?
     
  4. SkySeven

    SkySeven Baby Zombie

    Messages:
    145
    GitHub:
    SkySevenMC
    There is no error in the console: /
     
  5. TheDiamondYT

    TheDiamondYT Zombie

    Messages:
    298
    GitHub:
    TheDiamondYT1
    So you have an error but theres no error?

    Show us the whole file.
     
    Sandertv likes this.
  6. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    The point is what you expect to happen. The code looks perfectly valid to us, doing what the code should do. But that may not be what you expect to happen
     
    corytortoise and TheDiamondYT like this.
  7. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    Not necessarily. There is no context for the code. The whole thing may be inside a loop or switch function for all we know.
    Debug your plugin. Make sure you understand what conditional statements aren't returning like you expect it to.
     
  8. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    I added a bunch of var_dump statements for you. Maybe you can answer the questions I left in the comments too?
    PHP:
    $cdn $this->arenas[$level][1]; //array
    var_dump($cdn); //var_dump here to make sure $cdn is integer
    if($cdn == 0){ //here
        
    $block $lvl->getBlockIdAt($player->x$player->y-0.1$player->z);
        
    var_dump($block);
        if(
    $block == 355){
            if(
    $this->getTeam($player) == "blue"){
                echo 
    "blue"//echo here for debug
            
    }elseif($this->getTeam($player) == "red"){
                echo 
    "red";//echo here for debug
            
    }
            foreach(
    $lvl->getPlayers() as $pl){
                if(
    $this->getTeam($pl) == "blue"){ // is this CaSe sensitive?
                    
    $pl->teleport(new Position($config->get("spawnX-Blue"),$config->get("spawnY-Blue"),$config->get("spawnZ-Blue"),$this->getServer()->getLevelByName($config->get("Level")))); // why are there no defaults?
                
    }
                if(
    $this->getTeam($pl) == "red"){ // is this CaSe sensitive?
                    
    $pl->teleport(new Position($config->get("spawnX-Red"),$config->get("spawnY-Red"),$config->get("spawnZ-Red"),$this->getServer()->getLevelByName($config->get("Level")))); // why are there no defaults?
            
    }
        }
        
    $this->resetArena($arena $level); // is $level defined?
    }
     
    Last edited: May 8, 2017
    corytortoise likes this.
  9. SkySeven

    SkySeven Baby Zombie

    Messages:
    145
    GitHub:
    SkySevenMC
    Thanks for your answer, the error was fix but i don't know how !
     
  10. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    If your problem is solved, please mark the title as solved
     
    SkySeven likes this.
  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.