Jump to content

Arodang

Members
  • Posts

    1
  • Joined

  • Last visited

Reputation

0 Neutral

Profile Information

  • About me
    Curious George
  1. I know I'm a little late to this, but I just bought KSP and started programming the other day. Forgive me for any newbishness and all such. @Tor, while I'm no expert programmer or anything the code you posted earlier looks pretty good. The only thing I notice is that you have multiple print statements that you could combine together. The + operator concatenates strings together, like such: if (kerbal.rosterStatus == ProtoCrewMember.RosterStatus.MISSING) { print(kerbal.name + " is no more!"); kerbolist.Add(kerbal); } As far as OnSave and OnLoad methods, I've got a question about that as well. I wrote my first part mod yesterday and the basic idea is that this part takes a resource as input and spits out another resource (or two) as output; it's basically a sort of matter converter. Right now I have it hardcoded to use ElectricCharge to generate LiquidFuel and Oxidizer at a rate of 3 Electric per .5 LiquidFuel/Oxidizer. I thought, though, that it'd make more sense for the part to specify the rates at which it uses resources and attempted to implement an OnLoad() function to read the information from part.cfg and use those values. And that's where I ran into an issue. I followed the example in the Official Documentation thread but this is my first time programming for KSP and my first time using C#, so I'm not sure where the issue I'm having is originating from. Basically when I use node.GetValue() whatever I read in gets the default value for that variable type. class ElectricToFuelConverter : PartModule { [KSPField] public string resourceIn = "ElectricCharge"; public string resourceOut1 = "LiquidFuel"; public string resourceOut2 = "Oxidizer"; [KSPField(isPersistant=true)] public double resourceInAmount = 3; [KSPField(isPersistant = true)] public double resourceOutAmount = .5; [KSPField(isPersistant=true)] public bool generatorEnabled; //Do stuff in the middle to make it actually resource //Do more stuff in the middle public override void OnLoad(ConfigNode node) { string temp = node.GetValue("generatorEnabled"); print(temp); if (temp.Equals("true") == true) { Activate(); print("Loaded. Activating."); } else { Deactivate(); print("Loaded. Deactivating."); } print(node.GetValue("resourceInAmount")); print(node.GetValue("resourceOutAmount")); resourceInAmount = Convert.ToDouble(node.GetValue("resourceInAmount")); print("My resource in amount is " + resourceInAmount); resourceOutAmount = Convert.ToDouble(node.GetValue("resourceOutAmount")); print("My resource out amount is " + resourceOutAmount); } } Does anyone have any suggestions?
×
×
  • Create New...