Jump to content

[HELP!] How do I get the cost of a part?


Recommended Posts

I've encountered a weird problem. when I try to read a part config node, I can get the name and other values just fine but for some reason, "cost" isn't available - it's gone, as if KSP is masking this value for some reason.

does anyone know a reliable way to get the cost of a part?

Link to comment
Share on other sites

Can you find the part in PartLoader.LoadedPartsList?

	List<AvailablePart> parts = PartLoader.LoadedPartsList;
	for (int p = 0; p < parts.Count; ++p) {
		print($"Part {parts[p].name} cost: {parts[p].cost}");
	}
Quote

[LOG 14:00:28.765] Part kerbalEVA cost: 0
[LOG 14:00:28.765] Part kerbalEVAfemale cost: 0
[LOG 14:00:28.765] Part flag cost: 0
[LOG 14:00:28.765] Part mk1podNew cost: 600
[LOG 14:00:28.765] Part fuelTank100 cost: 150
[LOG 14:00:28.766] Part fuelTank200 cost: 275
[LOG 14:00:28.766] Part fuelTank400 cost: 500
[LOG 14:00:28.766] Part fuelTank800 cost: 800

...

 

Link to comment
Share on other sites

3 minutes ago, HebaruSan said:

List<AvailablePart> parts = PartLoader.LoadedPartsList;

four for four! you're on a roll, bro!

I didn't even know PartLoader existed. this will save me a TON of ConfigNode code.
THANKS!

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