Jump to content

The KSPField "Current Extension" is populated when the player looks at it, but empty when C# code looks at it. I'm confused.


Recommended Posts

So, the new piston parts in the Breaking Ground DLC have this string KSPField on the Part Action Window called "Current Extension".

This code is returning an empty string for the value shown in the PAW window even when the player sees a value there:

            // GetField() is explained below in the next Forum CODE box.
            // SuffixName is "Current Extension"
            BaseField field = GetField(suffixName);
            if (field == null)
                throw new KOSLookupFailException("FIELD", suffixName, this);
            if (!FieldIsVisible(field))
                throw new KOSLookupFailException("FIELD", suffixName, this, true);
            Object obj = field.GetValue(partModule));
            return obj;

When the above is run, the Type of obj is String, as expected, but its value is the empty string, even though this particular field on the PAW shows a value like "1.00021301m".  The exceptions shown above are *not* being thrown, so it's not that.

For reference, field.GetValue(PartModule m) is a built-in KSP API call - not something I wrote.
GetField(suffixName) is something I wrote, and it looks like this:
 

        /// <summary>
        /// Return the field itself that goes with the name (the BaseField, not the value).
        /// </summary>
        /// <param name="cookedGuiName">The case-insensitive guiName (or name if guiname is empty) of the field.</param>
        /// <returns>a BaseField - a KSP type that can be used to get the value, or its GUI name or its reflection info.</returns>
        protected BaseField GetField(string cookedGuiName)
        {
            return partModule.Fields.Cast<BaseField>().
                FirstOrDefault(field => string.Equals(GetFieldName(field), cookedGuiName, StringComparison.CurrentCultureIgnoreCase));
        }

I doubt that GetField() is failing, given that if it failed I should have thrown one of the two exceptions shown above.  It *does* find the KSPField who's gui name is "Current Extension", and it *is* reported as currently visible to the user, yet the value the user sees is "1.000511m" while the value the C# code sees when using GetValue() is "" (empty string).

Is there something new about how these fields on the DLC parts work?

Edited by Steven Mading
Link to comment
Share on other sites

Ah -Hah!  I found out the key:

The value remains empty string UNTIL you open the PAW, and THEN it populates.

Once you've opened the PAW once, then it keeps populating after that even if you close the PAW, but if you never opened the PAW yet during the current loaded scene, then the string is blank until you do.

Link to comment
Share on other sites

On 6/6/2019 at 3:09 AM, Steven Mading said:

Ah -Hah!  I found out the key:

The value remains empty string UNTIL you open the PAW, and THEN it populates.

Once you've opened the PAW once, then it keeps populating after that even if you close the PAW, but if you never opened the PAW yet during the current loaded scene, then the string is blank until you do.

Sigh  - Nope.  it keeps populating *for a while* with the PAW closed after it's opened.  But after some time it goes back to being frozen again until you open the PAW.

Link to comment
Share on other sites

  • 2 years later...

Sorry to Necro you,  but not sorry enough not to do it.   

Did you ever get C# control of the pistons?   I've got control of the hinges and rotational servos (but not the rotor hubs...  sigh) directly by setting targetangle values...   but setting target extension gets me nowhere!  I see the new value pop up the next time I open the PAW, but the piston ONLY moves if I drag the slider in the PAW with the mouse!

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.

 Share

×
×
  • Create New...