Comments (2)
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.
yup, that's how I do it.
from kos.
Related Issues (20)
- No way to read current nodeless encounter. HOT 1
- Could there be a way to read "Closest Approach"? HOT 4
- UNTIL will break at first chance. HOT 4
- v0.9.2 INLIGHT returns false negatives. HOT 1
- v0.9.2 kOS doesn't detect the reference transform has changed when the ship splits. HOT 4
- v0.9.2 alt:radar returns altitude when "too high" HOT 6
- Add page up + down to console editor
- Not working scripts HOT 4
- [Suggestion] Add ability to change max throttle of engines HOT 6
- Custom filetype HOT 5
- Prograde angles wrong below 70,000M on Kerbin. HOT 9
- Can't focus on kOS Terminal HOT 4
- Some kind of autoexec [enhancement] HOT 2
- Request: ISO-8601 time format HOT 1
- LIST FILES IN var. Does not work. HOT 3
- SHIP:FACING:PITCH supplying wrong values HOT 1
- setting node:eta does not do anything
- Terminal won't open HOT 1
- Add tab to KSC
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from kos.