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

Solved set item() Error

Discussion in 'Plugin Help' started by Fritures, Jun 1, 2019.

  1. Fritures

    Fritures Spider Jockey

    Messages:
    47
    So, hello everyone.
    I want to set items on an enderchest but i make this by an for() because It's so easily with this.
    But i get error
    My code :
    PHP:
    $i 3;
                for (
    $i 3$i =< 27 $i++) {
                    
    $inventory->setItem($iItem::get(160,15,1))
                }
    My error :
    Code:
    ParseError: "syntax error, unexpected ';', expecting ',' or ')'" (EXCEPTION) in "plugins/LunariaCore/src/LunariaCore/Others/EnderChest" at line 30
     
  2. BayAlper10

    BayAlper10 Silverfish

    Messages:
    17
    GitHub:
    BayAlper10
    Pls add ; for Item::get(160,15,1));
     
  3. iCirgio

    iCirgio Slime

    Messages:
    92
    GitHub:
    lolnova
    PHP:
                $i 0;
                while(
    $i 27) {
                    
    $inventory->setItem($iItem::get(160,15,1)); //don't recommend using digits for items use the item name example Item::get(Item::GLASS,15)
                
    }
                
    $i++
     
  4. Marabou

    Marabou Baby Zombie

    Messages:
    137
    GitHub:
    wiligangster
    No! loop "for" is more performance than while. and it's a bad practice to do that.
    While loops are used to repeatedly loop through steps "while" a specific condition is true
     
  5. Fritures

    Fritures Spider Jockey

    Messages:
    47
    Where ?
     
  6. Fritures

    Fritures Spider Jockey

    Messages:
    47
    I had this error :
    11:45:21] [Server thread/CRITICAL]: ParseError: "syntax error, unexpected ';', expecting ',' or ')'" (EXCEPTION) in "plugins/LunariaCore/src/LunariaCore/Others/EnderChest" at line 30

    With the code :
    PHP:
    for ($i 3$i =< 27 $i++) {
                    
    $inventory->setItem($iItem::get(Item::STAINED_GLASS,14,1));
                }
     
  7. Marabou

    Marabou Baby Zombie

    Messages:
    137
    GitHub:
    wiligangster
    you must change your operator in the loop =< to <= :facepalm:
     
  8. iCirgio

    iCirgio Slime

    Messages:
    92
    GitHub:
    lolnova
    PHP:
    for ($i 3$i <= 27$i++) {
                    
    $inventory->setItem($iItem::get(Item::STAINED_GLASS,14,1));
                }
     
  9. Fritures

    Fritures Spider Jockey

    Messages:
    47
    It's didn't work...
     
  10. iCirgio

    iCirgio Slime

    Messages:
    92
    GitHub:
    lolnova
    Dont copy and paste it :facepalm: type it out maybe that will fix the syntax error
     
  11. UnknownOre

    UnknownOre Silverfish

    Messages:
    21
    GitHub:
    UnknownOre
    post the whole function
     
  12. Fritures

    Fritures Spider Jockey

    Messages:
    47
    It's send to me "unexpected $inventory" :(
     
  13. Fritures

    Fritures Spider Jockey

    Messages:
    47
    PHP:
        public function onInventoryOpen(InventoryOpenEvent $event){

            
    $inventory $event->getInventory();
            
    $player $event->getPlayer();
            
            if(
    $inventory instanceof EnderChestInventory){
            
                
    /*if($player->hasPermission("ec.player")){*/
                
    $i 3;
                for(
    $i $i <= 27 $i++){
                    
    $inventory->setItem($iItem::get(Item::STAINED_GLASS,14,1));
                }
                
                
    //}
                
                /*elseif($player->hasPermission("ec.prince")){
                
                
                }
                
                elseif($player->hasPermission("ec.monarque")){
                
                
                }*/
                
                
            
    }
            

        }
     
  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.