Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Error in plugin

Comments in 'Plugin Development' started by Kabluinc, Aug 27, 2016.

  1. Kabluinc
    Offline

    Kabluinc New Member

    Joined:
    Mar 2, 2016
    Posts:
    29
    Minecraft User:
    Kabluinc
    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
  2. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    Can you please use the [ PHP ] [/ PHP ]?(without those spaces. Put your code inside.)
    Also, please point out the line.
  3. Kabluinc
    Offline

    Kabluinc New Member

    Joined:
    Mar 2, 2016
    Posts:
    29
    Minecraft User:
    Kabluinc
    Sorry. The line that the error is in is

    $gettheme = $themes->get("theme");
  4. JonsMC
    Offline

    JonsMC Active Member

    Joined:
    Jul 26, 2016
    Posts:
    107
    Minecraft User:
    JonsMC
    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
       
    ));
  5. JonsMC
    Offline

    JonsMC Active Member

    Joined:
    Jul 26, 2016
    Posts:
    107
    Minecraft User:
    JonsMC
    Sorry, change getthem into themes
  6. Kabluinc
    Offline

    Kabluinc New Member

    Joined:
    Mar 2, 2016
    Posts:
    29
    Minecraft User:
    Kabluinc
    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
    Last edited: Aug 27, 2016
  7. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    save theme array in local variable.
    PHP:
    $themes $config->getAll();

    //then you can get random theme 
    $theme $themes[array_rand($themes)];
    [
    PHP]
  8. SOFe
    Offline

    SOFe Banned

    Joined:
    May 28, 2016
    Posts:
    386
    Minecraft User:
    Herobrine
    WTF WTF WTF
    There was a $themes = new Config() line above it!
  9. JonsMC
    Offline

    JonsMC Active Member

    Joined:
    Jul 26, 2016
    Posts:
    107
    Minecraft User:
    JonsMC
    Read the reply after that :p i said change change $themes :p not creating a new one
  10. Kabluinc
    Offline

    Kabluinc New Member

    Joined:
    Mar 2, 2016
    Posts:
    29
    Minecraft User:
    Kabluinc
    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
  11. JonsMC
    Offline

    JonsMC Active Member

    Joined:
    Jul 26, 2016
    Posts:
    107
    Minecraft User:
    JonsMC
    Maybe try spacing between . And $buildingtheme? And why you need to add ""?
  12. Kabluinc
    Offline

    Kabluinc New Member

    Joined:
    Mar 2, 2016
    Posts:
    29
    Minecraft User:
    Kabluinc
    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
    Last edited: Aug 28, 2016
  13. JonsMC
    Offline

    JonsMC Active Member

    Joined:
    Jul 26, 2016
    Posts:
    107
    Minecraft User:
    JonsMC
    PHP:
    $player->sendMessage("Theme:" $buildingtheme);
  14. Kabluinc
    Offline

    Kabluinc New Member

    Joined:
    Mar 2, 2016
    Posts:
    29
    Minecraft User:
    Kabluinc
    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(09)];
    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?
  15. SOFe
    Offline

    SOFe Banned

    Joined:
    May 28, 2016
    Posts:
    386
    Minecraft User:
    Herobrine
    You bothered posting another post but didn't choose to edit the original post? Use the Edit button! :facepalm:
    Last edited: Aug 29, 2016
  16. JackboyPlay
    Offline

    JackboyPlay Active Member

    Joined:
    Apr 25, 2015
    Posts:
    507
    Minecraft User:
    JackboyPlay
    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);
  17. JackboyPlay
    Offline

    JackboyPlay Active Member

    Joined:
    Apr 25, 2015
    Posts:
    507
    Minecraft User:
    JackboyPlay
    The first } is the problem
  18. Ragnok1234
    Offline

    Ragnok1234 Active Member

    Joined:
    Jul 18, 2016
    Posts:
    53
    Minecraft User:
    Ragnok123
    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"
  19. Ragnok1234
    Offline

    Ragnok1234 Active Member

    Joined:
    Jul 18, 2016
    Posts:
    53
    Minecraft User:
    Ragnok123
    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(13){
    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]
  20. Ragnok1234
    Offline

    Ragnok1234 Active Member

    Joined:
    Jul 18, 2016
    Posts:
    53
    Minecraft User:
    Ragnok123
    Oh, somethink is wrong!!!
    On first line is:
    PHP:
    $rand=mt_rand(13);
    I forgotted it, sorry

Share This Page

Advertisement