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($i, Item::get(160,15,1)) } My error : Code: ParseError: "syntax error, unexpected ';', expecting ',' or ')'" (EXCEPTION) in "plugins/LunariaCore/src/LunariaCore/Others/EnderChest" at line 30
PHP: $i = 0; while($i < 27) { $inventory->setItem($i, Item::get(160,15,1)); //don't recommend using digits for items use the item name example Item::get(Item::GLASS,15) } $i++
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
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($i, Item::get(Item::STAINED_GLASS,14,1)); }
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 = 3 ; $i <= 27 ; $i++){ $inventory->setItem($i, Item::get(Item::STAINED_GLASS,14,1)); } //} /*elseif($player->hasPermission("ec.prince")){ } elseif($player->hasPermission("ec.monarque")){ }*/ } }