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

Why $z is allways 1

Discussion in 'Development' started by Hoyee, Mar 6, 2020.

  1. Hoyee

    Hoyee Baby Zombie

    Messages:
    126
    switch ($z){

    case 1:
    $player->sendMessage("1");
    if($z==1){
    $z=$z+1;
    }
    break;

    case 2:
    $player->sendMessage("2");
    if($z==2){
    $z=$z+1;
    }
    break;

    case 3:
    $player->sendMessage("3");
    if($z==3){
    $z=$z+1;
    }
    break;

    }


    It allways sendMessage "1"
     
    Last edited: Mar 6, 2020
  2. GamakCZ

    GamakCZ Zombie Pigman

    Messages:
    598
    GitHub:
    GamakCZ
    could you send the full code? This should work, if you use the function for more time (eg. in while() loop)
     
  3. Hoyee

    Hoyee Baby Zombie

    Messages:
    126
    Here is.


    public function onTouch(PlayerInteractEvent $event){
    $p = $event->getPlayer();
    $z = 1;

    for($i=0; $i<=5; $i=$i+0.2){

    $x = cos(($p->yaw+90)*M_PI/180)*$i+$p->x;
    $z = sin(($p->yaw+90)*M_PI/180)*$i+$p->z;
    }

    $dz1=$p->getLevel()->addParticle(new FlameParticle(new Vector3($x,$p->y+1.7,$z)));
    $dz2=$p->getLevel()->addParticle(new FlameParticle(new Vector3($x,$p->y+1.7,$z)));
    $dz3=$p->getLevel()->addParticle(new FlameParticle(new Vector3($x,$p->y+1.7,$z)));

    switch ($z){

    case 1:
    if($p->getInventory()->getItemInHand()->getId() == 280){
    $dz1;
    }
    $p->sendMessage("1");
    if($z==1){
    $z=$z+1;
    }
    break;

    case 2:
    if($p->getInventory()->getItemInHand()->getId() == 280){
    $dz2;
    }
    $p->sendMessage("2");
    if($z==2){
    $z=$z+1;
    }
    break;

    case 3:
    if($p->getInventory()->getItemInHand()->getId() == 280){
    $dz3;
    }
    $p->sendMessage("3");
    if($z==3){
    $z=1;
    }
    break;

    }
     
  4. GamakCZ

    GamakCZ Zombie Pigman

    Messages:
    598
    GitHub:
    GamakCZ
    Are you sure with the result?
     
  5. GamakCZ

    GamakCZ Zombie Pigman

    Messages:
    598
    GitHub:
    GamakCZ
    You have to put the switch into the loop if you want to call the code more times
     
  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.