Jump to content

[ANSWERED] part.Resources, Remove item

Recommended Posts

In my mod GTI MultiMode Intakes, I am allowing switching between different intake modes. When doing this, I'm also changing the resources associated with the intake, like intakeair or intakeatm. However, so far, I've relied on "part.Resources.Clear();". This removes all resources in the part, and then I can add the new resource I want back in.

However, this have one mayor drawback, it removes all resources, and not just the ones I want it to, namely the ones I target.

So in my latest try, I used the below methods to target only relevant resources. However, I cannot seem to get them to work.

    public bool Remove(PartResource res);
    public bool Remove(string resName);
    public bool Remove(int resID);

I tried as follows (i merged the three overload methods directly into the example below, I do NOT run them at the same time, I comment out when testing). Debug messages says that I do indeed run the "Remove()" method where expected and on the expected resource. The remove methods return true!!! But my engine continues to consume IntakeAir even when switched away, so that the resource should have been removed. When I use "Clear()" the engine flameout immediately as it should. And listing all resources in the part after all show that the resource was not removed.

bool preserveResource;
PartResource partResourceDef;
//Evaluated all resources in part
for (int i = 0; i < currentPart.Resources.Count; i++)
	preserveResource = true;
	GTIDebug.Log("Check for resource removal: " + currentPart.Resources[i].resourceName, iDebugLevel.DebugInfo);
	//compare all resources to the target resources
    	for (int j = 0; j < modes.Count; j++)
		//If it is a target resource, mark it for replacement
		if (modes[j].resourceName == currentPart.Resources[i].resourceName)
			//Remove resources managed by this mod
			preserveResource = false;
	//Remove resource if it is marked for replacement
	if (!preserveResource)
		GTIDebug.Log("Removing Resource: " + currentPart.Resources[i].resourceName, iDebugLevel.DebugInfo);
		//try 1
		//try 2
		//try 3
		partResourceDef = currentPart.Resources.Get(currentPart.Resources[i].resourceName);

So my questions are,

  • does Remove() work at all?
  • if yes, then can anybody point me toward what could be wrong in my code?


Edited by Warezcrawler
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.

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