KSP-KOS / KOS

Fully programmable autopilot mod for KSP. Originally By Nivekk
Other
697 stars 230 forks source link

ASSERT function #743

Open geoffromer opened 9 years ago

geoffromer commented 9 years ago

It would be quite useful if KerboScript had an ASSERT function. The idea would be that if its argument is true, it has no effect, but if its argument is false, the script terminates with an error message that points to the failing assertion. This would let you do all kinds of useful parameter and state validation without having to "protect" everything after the check, or otherwise arrange proper flow control for the error case. Something similar is discussed in #125, but there it gets entangled with the whole function-call can of worms. I think that's unnecessary for this use case: an ASSERT should terminate not only the immediate function, but all its callers as well, so the question of return values does not arise.

Not only would this be a very useful feature, it also seems appealing from an RP point of view: assertions strike me as a very Kerbal form of error handling.

abenkovskii commented 9 years ago

@erendrake Can I make it?