Jump to content

Best way to request electric charge from the vessel?


Recommended Posts

Hi all,

I am stumped on this one. What I've tried thus far isn't working for me and I'm sure there's something simple I'm missing. Is there a way for a part module to request electric charge from the vessel, and not just the part's resource? Thanks for the help! :)

Link to comment
Share on other sites

HI newbie here.

Do you have to iterate part.RequestResource for all parts? Am I even asking the right question?

No, you just call it on the part that you are drawing the resource from which is usually the part your module is a part of, e.g. ModuleEngines calls it on the engine part itself. It then uses either the defined flow rule for the resource or the specific flow rule you specify in the call to take the resource from whatever part(s) on the vessel it should.

Also note that there is at least one bug in RequestResource when using the ALL_VESSEL or STAGE_PRIORITY rules. See this thread for details but basically you will sometimes not get the amount you request even though it is available in the vessel. You must always check the value returned from the function which tells you how much you were actually given...

Edited by Padishar
Link to comment
Share on other sites

Maybe I'm misunderstanding but I thought OP wanted to get electric charge value for the whole vessel.

Also see which thread?

Ahhh, I see what you mean. Yes, RequestResource is used to actually remove (or add) resources to a vessel via the particular part following the resource flow rules. If you just want to know how much electric charge is on the whole vessel then you will have to add it up. This either means looping through the whole part list and adding it all up, taking care to check the disabled flags etc., or calling Part.GetConnectedResources to get a list of the resources actually available to a particular part and iterating through that list instead (much easier but may cause lots of garbage collection if called often for large vessels).

Seems I forgot to add the link, sorry and fixed.

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