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

Solved Fatal error: Call to a member function get()

Comments in 'Plugin Development' started by TheKillerTacos, May 11, 2016.

  1. TheKillerTacos
    Offline

    TheKillerTacos Active Member

    Joined:
    Jan 21, 2016
    Posts:
    76
    Minecraft User:
    TheKillerTacos
    So, I was making a Temporal MultiLanguage support for my Skyblock plugin, and this showedup:

    Fatal error: Call to a member function get() on resource in phar://C:/Users/#######/Desktop/CS/plugins/SkyBockXT.phar/src/SkyBlockXT/Main.php on line 65

    Here is Line 65:
    PHP:
    $info_pluginloaded $this->getResource("/Lang-".$defLang.".yml")->get("INFO.PluginLoaded"); //Line 65
    $this->getLogger()->info(TextFormat::BLUE $info_pluginloaded); //Line 66
    and you may ask, Where is $deflang? its on line 43, so its not giving error on that:
    PHP:
    $defLang $this->getConfig()->get('Language');
    So any solution? cant think of a fix! :(

    Here is the whole Repo if you want to find out More:
    https://github.com/TKRT-Creations/SkyBlockXT

    Still working on generator, but cant debug if i dont fix this :(
    Last edited: May 11, 2016
  2. Extreme_Heat
    Offline

    Extreme_Heat Active Member

    Joined:
    Apr 19, 2016
    Posts:
    76
    Minecraft User:
    Extreme_Heat
    getResource() does not return a Config object, it returns a file handle for a resource.

    You need to manually create a PocketMine Config object from that file.
  3. TheKillerTacos
    Offline

    TheKillerTacos Active Member

    Joined:
    Jan 21, 2016
    Posts:
    76
    Minecraft User:
    TheKillerTacos
    So, would it be $this->getConfig("/Lang-".$defLang.".yml")->get("INFO.PluginLoaded"); ?
  4. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    No, it would be
    PHP:
    /** \pocketmine\utils\Config */
    $defLang = new Config("/Lang-".$defLang.".yml"Config::YAML); // yaml_parse parsed
    $defLang->get('key');
  5. TheKillerTacos
    Offline

    TheKillerTacos Active Member

    Joined:
    Jan 21, 2016
    Posts:
    76
    Minecraft User:
    TheKillerTacos
    ehm, $deflang is to name default language that its on config.yml : Lang-eng.yml (eng is default on config) but when i try to get-> on Lang-eng.yml, it gives that error so thats actually wrong i guess, since $deflang = $this->getConfig("Language"); and im wanting to get from the file Lang-$deflang.yml the message INFO.PluginLoaded, and INFO.PluginLoaded is:
    Code:
     INFO.PluginLoaded: Plugin Loaded succesfully! Language selected: English
    
    From Lang-eng.yml, so How do i find INFO.PluginLoaded on Lang-eng.yml? if get->() Doesnt Works?

    Might $this->getFile("/Lang-eng.yml")->get("INFO.PluginLoaded"); Work?
  6. TheKillerTacos
    Offline

    TheKillerTacos Active Member

    Joined:
    Jan 21, 2016
    Posts:
    76
    Minecraft User:
    TheKillerTacos
    So could it be:
    PHP:
    $defLang $this->getConfig("Language");
    $langFile = new Config("/Lang-".$defLang.".yml"Config::YAML);
    $info_pluginloaded $langFile->get("INFO.PluginLoaded");
    $this->getLogger()->info(TextFormat::BLUE $info_pluginloaded);
    And output should be:
    Plugin Loaded succesfully! Language selected: English
  7. TheKillerTacos
    Offline

    TheKillerTacos Active Member

    Joined:
    Jan 21, 2016
    Posts:
    76
    Minecraft User:
    TheKillerTacos
    UPDATE: i tried that, it just give blank output
  8. Extreme_Heat
    Offline

    Extreme_Heat Active Member

    Joined:
    Apr 19, 2016
    Posts:
    76
    Minecraft User:
    Extreme_Heat
    getConfig() takes no arguments.

    You also need to get your plugin's data folder when you are initializing Config, otherwise the PocketMine directory will be used. (Not to mention, that "/" you're uing represents an absolute path)

    Do something like

    PHP:
    $lang_file $this->getDataFolder() . $filename;
    if (!
    file_exists($lang_file)) {
        
    //  handle non existing file
    }
    $this->lang_conf = new Config($lang_file);

    ...

    echo 
    $this->lang_conf->get('key');
  9. TheKillerTacos
    Offline

    TheKillerTacos Active Member

    Joined:
    Jan 21, 2016
    Posts:
    76
    Minecraft User:
    TheKillerTacos
    Wait, I used the / because in some code it gave problems, so ill just try removing it to see if it works, Totally forgot about that
    Last edited: May 12, 2016
  10. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    Take a look at here

Share This Page

Advertisement