Giter Site home page Giter Site logo

Comments (2)

Dunbaratu avatar Dunbaratu commented on August 13, 2024

The fact that the type returned when you say "encounter" changes depending on if there's an encounter or there isn't is really annoying. If it exists, then it's an orbitinfo. If it does not exist then it's a string. But you need to write code that handles both cases and doesn't bomb out with error when testing for whether an encounter exists or not. But you don't know which way to write the syntax until after you discover if the encounter is "None" or not, and you can't discover if it's "None" or not until you write the syntax and execute it.

The only solution I've found that works around this is to create a de-facto "casting to string" by doing this:
The expression ("" + encounter) is always reliably a string regardless of whether or not encounter is "None" or is a real body. This is because when it's a string then you add "None" to null string and get "None", whereas when it's a real body, the act of adding an orbitinfo to a string forces the system to run the orbitinfo.toString method to get its string name out, so it's like casting encounter to a string.

So this: (""+encounter)
is always a string no matter what, enabling you to make your check work this way:

if "" + encounter == somebody.name {….}.
Where somebody is Mun, or Minmus, or whatever.

And then if you do want to look at the parts of the orbitinfo structure, you can protect those checks like so:

isEnc on.
if "" + encounter == "None" { isEnc off. }.
if isEnc {
// There is an encounter, so do something with it here.
}.

(The reason for the strange extra lines of logic there is because there's no such thing as a "not" operator in kOS , nor a not-equal-to operator, nor an 'else' statement.)

from kos.

JoCRaM avatar JoCRaM commented on August 13, 2024

yup, that's how I do it.

from kos.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.