Hello there,
i've two plugins and i want from plugin 1 the dictionary in plugin 2.
What i do:
Plugin 1 Public function to return the Dict prison
Plugin 2: Get Dict prisonCode:public Dictionary<BasePlayer, float> return_prison() { return prison; }
But i get everytime a (NullReferenceException: Object reference not set to an instance of an object). What do i wrong?Code:[PluginReference] Plugin RHPrison; var prison = (Dictionary<BasePlayer, float>)RHPrison?.Call("return_prison"); if (prison.ContainsKey(player)) { ....... }
NRE with plugin reference / hook function
Discussion in 'Rust Development' started by Sir BenSon, Jan 13, 2017.
-
Wulf Community Admin
I would avoid casting or calling it if it is null, cast later and check for null before using it.
-
Ah okay..
Code:var prison = (Dictionary<BasePlayer, float>)RHPrison?.Call("return_prison"); if(prison != null) { if (prison.ContainsKey(player)) { } }
-
Any possibilities for the entire code? It's not that easy to say what's wrong with only parts of it.
-
This is the full part. plugin 1 returns the dict with baseplayer and float. But it doesnt call the fuction in the plugin. i dont understand this
How to call a function from plugin 2 in plugin 1?
EG:
Plugin 1 function:
public string(ulong id)
{
return string
}
plugin2 ?
What to do? -
Actually just noticed you declared your method public, Call in conjunction with PluginReference is only able to call methods that are declared private. So above code should work fine if you would change your return_prison() method from public to private.
-
Yeah change from public to private works fine Thanks . But why?