Jump to content

The official unoffical "help a fellow plugin developer" thread


Recommended Posts

How do you access a config node? I've been using this code but can't seem to figure it out:

public class BPManagedResource
{
    //public string ManagedResource = ConfigNode.GetNode("BPManagedResource");
    public void OnLoad(ConfigNode BPManagedResourceNode)
    {
        string BPManagedResourceValueHelper = BPManagedResourceNode.GetValue("BPManagedResource");
    }
    public string BPManagedResourceValue = BPManagedResourceValueHelper
}

But it keeps giving this error: 

Error    CS0103:

   The name 'BPManagedResourceValueHelper' does not exist in the current context 

Link to comment
Share on other sites

On 6/7/2024 at 12:34 AM, KspNoobUsernameTaken said:

Error    CS0103:

   The name 'BPManagedResourceValueHelper' does not exist in the current context

This indicates that the variable name has exited the scope. If you look at the curly brackets, the variable BPManagedResourceValueHelper was defined inside the function OnLoad. If you try to use it outside of that function, there's no way for the compiler to know what variable you're talking about (since there might be other functions with variables with the same name in them, or indeed none at all).

Instead, you need to define BPManagedResourceValue in the class scope, as you have, and then set it in the function scope (since that's where […]Helper is defined). Order shouldn't matter here, but it's considered good practice to put your class variables ("fields") above your class functions ("methods"), so you can immediately see all the fields of a class.

Link to comment
Share on other sites

7 minutes ago, 0111narwhalz said:

This indicates that the variable name has exited the scope. If you look at the curly brackets, the variable BPManagedResourceValueHelper was defined inside the function OnLoad. If you try to use it outside of that function, there's no way for the compiler to know what variable you're talking about (since there might be other functions with variables with the same name in them, or indeed none at all).

Instead, you need to define BPManagedResourceValue in the class scope, as you have, and then set it in the function scope (since that's where […]Helper is defined). Order shouldn't matter here, but it's considered good practice to put your class variables ("fields") above your class functions ("methods"), so you can immediately see all the fields of a class.

Thank you, but I think I solved this. It is still quite helpful.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...