Skip to content

Fix #3006: convert suffix arguments to booleans like conditions do - #3206

Open
sparr wants to merge 1 commit into
KSP-KOS:developfrom
sparr:doaction-scalar-bool
Open

sparr wants to merge 1 commit into
KSP-KOS:developfrom
sparr:doaction-scalar-bool

Conversation

@sparr

@sparr sparr commented Oct 19, 2026

Copy link
Copy Markdown

Fixes #3006.

Currently, passing a non-boolean to a function that expects a boolean fails with Specified cast is not valid. The docs say that a number should be usable where a boolean is expected.

This PR converts to boolean the same way it's already done in logical conditions, and will still emit Cannot use SOMETYPE where boolean is needed for other types.

AI Disclosure The code and commit message are by Claude Opus 5.5. I've tested in-game and confirmed the expected behavior, and I wasn't able to produce any unexpected side effects. I reviewed the code here and wrote this PR description based on my understanding of it.

…s do

Convert.ChangeType() maps every Structure type to TypeCode.Object and
returns the argument unchanged, so a scalar passed to a suffix that
takes a BooleanValue, such as DOACTION("name", 1), reached the suffix's
cast and threw a bare InvalidCastException. Convert such arguments with
Convert.ToBoolean(), matching how conditions treat scalars and strings.

Arguments that still do not match a Structure parameter type now throw
KOSCastException instead of the InvalidCastException.

Fixes KSP-KOS#3006

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DOACTION passing scalar 1 to mean "true" throws casting error. WAS: "Can't use action in other language"

1 participant