Skip to content

ENCOUNTER's inconsistet object type makes it imposssible to check against. #243

@Dunbaratu

Description

@Dunbaratu

If you check the value of ENCOUNTER to find out if you have an encounter, you just can't seem to do it because whether you do or do not have an encounter will change the TYPE returned by ENCOUNTER, making KOSscript complain one way or the other.

So how do I test if there's an encounter?

This statement will give a runtime error if there IS an encounter:
if ENCOUNTER = "None" { ..whatever.. }.
and this one will give a runtime error if there is NOT an encounter:
if ENCOUNTER:body = myIntendedBody { ...whatever... }.

Because in order to tell you that there's no encounter, ENCOUNTER returns a String containing "None" as its value, but if there is an encounter, then ENCOUNTER returns an OrbitInfo which is not allowed to be compared to a String.

KOSscript doesn't have reflection. You can't ask "what is the type of this object?' as a means of performing the test. You have to assume you know the type and write the code accordingly.

As far as I can tell, this is an impossible to work around problem at the moment. (If anyone has a workaround please let me know. I need this for my entry into ThrFoot's challenge contest.)

I suggest one of these two approaches:
1: Just like ENCOUNTER can pretend it's a string when it's the subject of a PRINT statement, also make it pretend it's a string (giving the value of the encounter body's name) when it's the subject of a comparator, so it will allow you to compare it to "None" to find out if it's a real encounter before then trying to access its suffix parts.
(or)
2: Make a dummy OrbitInfo object to be returned when there's no encounter, so that ENCOUNTER still has the suffix parts BODY, PERIAPSIS, and APOAPSIS that you can compare against, but they contain dummy values.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions