Jump to content

PartModuleList.Contains and Game mode


Recommended Posts

1) PartModuleList.Contains

I recently ran into an issue with Filter Extensions whereby a part module calling Destroy() on itself during it's awake sequence resulted in exceptions when part.Modules was queried with a string or int parameter.

// breaks
part.Modules.Contains("PartModule");
part.Modules.Contains("PartModule".getHashCode());
// works
part.Modules.Contains<PartModule>();

Which is all well and good, except querying by string/int is rather necessary for non-stock modules

My solution currently is to check against PartModule.GetType().Name, but I was wondering if there was any other ways that I should be looking at (particularly since the module type check is probably the most frequently used for FE by a good stretch). I'd be particularly interested in a solution that allows for derived classes like the typed check above (ie. how Contains<ModuleEngines>() also catches ModuleEnginesFX) because it'd be nice to have consistency with the stock modules (and my current method for going from a string to typed check for stock is a PITA to maintain...)

2) Game mode

How do we tell when the game is a scenario/training module?

Edited by Crzyrndm
Link to comment
Share on other sites

19 hours ago, Crzyrndm said:

1) PartModuleList.Contains

I recently ran into an issue with Filter Extensions whereby a part module calling Destroy() on itself during it's awake sequence resulted in exceptions when part.Modules was queried with a string or int parameter.


// breaks
part.Modules.Contains("PartModule");
part.Modules.Contains("PartModule".getHashCode());

Which is all well and good, except querying by string/int is rather necessary for non-stock modules

I've never had any problem at all with these methods, whatsoever. What exactly is breaking?

Link to comment
Share on other sites

11 minutes ago, Crzyrndm said:

Not mine, RPM is the one causing the issues (or rather mods that haven't updated to match RPM yet)

That is... odd. At this point I guess you could nearly work with a very specific exception for this case, else I believe this walks into the realm of reflection

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