Hi, im getting this error in my plugin Notice: Undefined variable: gettheme in C:\Users\server\Desktop\servers\test\plugins\BuildBattle_v1.0 (1)\src\Kabluinc\BuildBattle\BuildBattle.php on line 645 My code is $type = ("car"); $themes = new Config($this->plugin->getDataFolder() . "/themes.yml", Config::YAML); $themes->set("theme", $type); $themes->save(); $gettheme = $themes->get("theme"); } if($timeToStart<=0) { foreach($playersArena as $pl) { $pl->sendPopup($gettheme); And the config created was --- theme: car ... Why am i getting that error? ik theres no point in having $gettheme but still why doesnt it work
Can you please use the [ PHP ] [/ PHP ]?(without those spaces. Put your code inside.) Also, please point out the line.
The themes in config wasn't set when the config file was created, add it using: PHP: $gettheme = new Config($this->plugin->getDataFolder() . "/themes.yml", Config::YAML, array ( "themes" => car ));
Actually, how can i get the plugin to choose a random theme and display it on a popup? iv tried Setting config with --- themes: - car - boat - park ... How do i get a random theme from the themes.yml and player->sendPopup without it refreshing with a new random theme every tick. That what happened when i last tried it. Every second it keeps looping and getting a new random theme
save theme array in local variable. PHP: $themes = $config->getAll();//then you can get random theme $theme = $themes[array_rand($themes)];[PHP]
Pls help me with this Ok so when the plugin loads.. this code is run PHP: $themes = new Config($this->getDataFolder() . "/themes.yml", Config::YAML); $theme = array(array("Puppy"),array("IceCream"),array("Herobrine"),array("Computer"),array("Laptop"),array("car"),array("Spongebob"),array("Squid"),array("Wolf"),array("Ocelot")); if($themes->get("Themes")==null) { $themes->set("Themes",$theme); } $themes->save(); Then this code is run before game start PHP: $themes = new Config($this->plugin->getDataFolder() . "/themes.yml", Config::YAML); $theme = $themes->getAll(); $buildingtheme = $theme[array_rand($theme)]; But when i use $buildingtheme when the game starts to display a theme on $player->sendMessage("Theme" .$buildingtheme . ""); Ingame it displays blank for theme and in console it shows Notice: Undefined variable: buildingtheme in C:\Users\server\Desktop\servers\test\plugins\BuildBattle_v1.0 (1)\src\Kabluinc\BuildBattle\BuildBattle.php on line 645
Using this PHP: $player->sendMessage("Theme:" . $buildingtheme .); Crashed the server with error: Server thread/CRITICAL]: ParseError: "syntax error, unexpected ')'" (EXCEPTION) in "/plugins/BuildBattle_v1.0 (1)/src/Kabluinc/BuildBattle/SkyWars" at line 698 Using PHP: $player->sendMessage("Theme:" .$buildingtheme . ""); The server loads, game starts but it displays Theme: (nothing) And in console undefined variable $buildingtheme error What shud i do
Nope. That still showed the undefined variable error Now one thing i found does work is this before game start PHP: $themes = array("Botanic Garden", "Witches Hut", "Mobile Phone", "Christmas tree", "Sea Side", "Cake", "Wind Mill", "Statue of yourself", "Cup cake", "Shed"); $theme = $themes[rand(0, 9)]; Then i used PHP: $player->sendPopup("Theme:" . $theme); It shows themes correctly but it keep changing the theme to a new random one each tick. So the popup doesnt stay to just one theme. How to fix this?
You bothered posting another post but didn't choose to edit the original post? Use the Edit button! :facepalm:
PHP: $type = ("car");$themes = new Config($this->plugin->getDataFolder() . "/themes.yml", Config::YAML);$themes->set("theme", $type);$themes->save();$gettheme = $themes->get("theme");} //You closed it and want to use it after this line?!?if($timeToStart<=0){foreach($playersArena as $pl){$pl->sendPopup($gettheme);
T True. But you can also PHP: $type = ("car");$themes = new Config($this->plugin->getDataFolder() . "/themes.yml", Config::YAML);$themes->set("theme", $type);$themes->save();$gettheme = $themes->get("theme");if($timeToStart==0){foreach($playersArena as $pl){$pl->sendPopup($gettheme);}} Originally when someone develops an plugin, or somethink another, he doesnt write "{" before "if"
And I'm not master with configs, but I think, that you selected all words in "themes". If you making this for yourself, I recomended: PHP: $rand=mt_rand(1, 3){switch($rand){case 1:$theme = §6Car;break;case 2:$theme = §6Tank;break;case 3:$theme = §6Build anythink what you want;break;}if($timeToStart<=0){foreach($playersArena as $pl){$pl->sendPopup("§bTheme" .$theme.);[}}/PHP]