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

Why this is not working?

Discussion in 'Development' started by tybikman, Feb 18, 2021.

  1. tybikman

    tybikman Silverfish

    Messages:
    22
    This code should spawn the structure, but it will only spawn one block
    PHP:
    public function spawnStructure(Vector3 $posLevel $lvint $id) : void{
            
    $structure=$this->getStructure($id);
            
    $blocks=$structure->getBlocks();
            foreach(
    $blocks as $blstr){
                
    $arr=explode(','$blstr);
                
    $x=str_replace("x"$pos->getX(), $arr[0]);
                
    $y=str_replace("y"$pos->getY(), $arr[1]);
                
    $z=str_replace("z"$pos->getZ(), $arr[2]);
                
    $lv->setBlock(new Vector3($x$y$z), Block::get($arr[3]));
            }
        }
    blocks array be like:
    ["x, y+1, z-1, 54"]

    I m really dont know why this is not working.
    Thanks for help
     
  2. ethaniccc

    ethaniccc Baby Zombie

    Messages:
    189
    GitHub:
    ethaniccc
    What did you want the code to do? What did the code actually do?
     
  3. tybikman

    tybikman Silverfish

    Messages:
    22
    This code should spawn the structure, but it will spawn only one block of all (the last one), the getBlocks () function returns an array of blocks that looks something like this:
    ["x, y+1, z, 54", "x-2, y, z, 87", "x, y, z, 56"]
     
  4. wolfdale

    wolfdale Zombie Pigman

    Messages:
    535
    GitHub:
    diamond-gold
    It doesnt evaluate the expression string, Im surprised you can even run that code
    You cant pass something like "5+1" when it expects an int, it wont do the addition for you :facepalm:
     
    Primus and tybikman like this.
  5. tybikman

    tybikman Silverfish

    Messages:
    22
    How to fix this ?
     
  6. tybikman

    tybikman Silverfish

    Messages:
    22
  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.