Jump to content

Delete a specific confignode


Recommended Posts

Alright, this seems like it should be so simple, but I'm drawing a blank.

I have a ConfigNode with 3 sub-nodes that are all named "PART".

As a value on each PART sub-node I have the flightID as a unique value.

I want to delete one of the PART sub-nodes based on this flightID value, how do I go about it?

The closest I've come up with so far is the following:

foreach(ConfigNode nList in masterNode.nodes)
{
if(nList.GetValue("FlightID") == FlightIDOfPartToDelete)
{
masterNode.RemoveNode(nList); //does not work because RemoveNode only takes a string
}
}

So I'm stuck. I'm pretty sure I'm missing a command or method that would allow me to do this but looking at the object browser I'm coming up blank.

Anyone have any ideas?

D.

Link to comment
Share on other sites

This seems so absurdly simple I'm almost embarrassed to suggest it (particularly given the amount of help you've given me with my code), but... will masterNode.RemoveNode(nList.ToString()); work?

I don't know enough about confignodes to test it myself I'm afraid, I'm still a little baffled by them beyond grabbing stuff out of config files.

Apologies if that's a complete waste of a post, it may have been so obvious you didn't mention having tried it :rolleyes:

Link to comment
Share on other sites

Unfortunately not, configNode.RemoveNode(string); removes the first node in the list with that name as string. Your example would not match anything as it would pass the entire node as a string, not just the name.

In my case, all of my nodes are named PART so that would simply delete the first node in the list.

As as work around, I'm currently walking the list, copying all nodes that don't match to a temporary list, deleting all the nodes in the masterNode and then adding them back from the temporary list. (Testing pending, I'm not sure I've got the object linking right yet.)

D.

Link to comment
Share on other sites

In mm I use nodes.Remove(subNode)

If you do that you can't iterate on the original list so from memory and no compiler to test

foreach(ConfigNode nList in masterNode.nodes.toList() )

{

if(nList.GetValue("FlightID") == FlightIDOfPartToDelete)

{

masterNode.nodes.Remove(nList); //does not work because RemoveNode only takes a string

}

}

Link to comment
Share on other sites

Wait, I can work standard list operations on ConfigNode.nodes without issue? I was assuming I had to use .addNode and .removeNode methods to avoid causing errors (due to behind the scenes code not exposed).

That makes things much simpler, testing pending of course.

Thanks for that,

D.

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

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...