KSP-KOS / KOS

Fully programmable autopilot mod for KSP. Originally By Nivekk
Other
691 stars 229 forks source link

If throttle was never set (by hand or script) there will be an error if it is accessed. Is this intended behavior? #990

Closed Feinbube closed 8 years ago

Feinbube commented 9 years ago

kOS Operating System KerboScript v0.17.2

Proceed. print throttle. Object reference not set to an instance of an object At interpreter history, line 1 print throttle. ^

abenkovskii commented 9 years ago

It probably is because there is no such thing as throttle variable before you lock it (setting throttle does nothing!). If you want to get the current throttle try using this: http://ksp-kos.github.io/KOS_DOC/commands/flight/pilot.html#ship-control-pilotmainthrottle or this: http://ksp-kos.github.io/KOS_DOC/commands/flight/raw.html#ship-control-mainthrottle. I'm not sure what is the difference because I never used mainthrottle.

abenkovskii commented 9 years ago

Note: one more cryptic error message. Could you send us your KSP_Data\output_log.txt where this error is the last one to happen?

Feinbube commented 9 years ago

What I intended to do was to create a HUD in putty showing me current infos about the ship. Both, Mainthrottle and Throttle seem to be problematic: https://github.com/KSP-KOS/KOS/issues/991

Feinbube commented 9 years ago
KSP_Data\output_log.txt:

kOS: At interpreter history, line 1
print throttle.
      ^

(Filename: C:/buildslave/unity/build/artifacts/StandalonePlayerGenerated/UnityEngineDebug.cpp Line: 56)

System.NullReferenceException: Object reference not set to an instance of an object

  at kOS.Function.FunctionPrint.Execute (kOS.SharedObjects shared) [0x00000] in <filename unknown>:0 

  at kOS.Function.FunctionManager.CallFunction (System.String functionName) [0x00000] in <filename unknown>:0 

  at kOS.Execution.CPU.CallBuiltinFunction (System.String functionName) [0x00000] in <filename unknown>:0 

  at kOS.Safe.Compilation.OpcodeCall.Execute (ICpu cpu) [0x00000] in <filename unknown>:0 

  at kOS.Execution.CPU.ExecuteInstruction (IProgramContext context) [0x00000] in <filename unknown>:0 

(Filename: C:/buildslave/unity/build/artifacts/StandalonePlayerGenerated/UnityEngineDebug.cpp Line: 56)

Code Fragment

File                 Line:Col IP   opcode operand

----                 ----:--- ---- --------------------- 

                        0:0   0000 jump 1 

interpreter history     1:1   0001 push $<argstart> 

interpreter history     1:7   0002 push $throttle 

interpreter history     1:7   0003 call print() <<--INSTRUCTION POINTER--

interpreter history     1:7   0004 pop 

                        0:0   0005 EOF 

(Filename: C:/buildslave/unity/build/artifacts/StandalonePlayerGenerated/UnityEngineDebug.cpp Line: 56)

kOS: Stack dump: stackPointer = 0

000 SP-> $<argstart>

(Filename: C:/buildslave/unity/build/artifacts/StandalonePlayerGenerated/UnityEngineDebug.cpp Line: 56)
abenkovskii commented 9 years ago
  1. I'd recommend wrapping the whole log with ``` (one before and one after the log): Without it github formatting "eats" parts of your log.
  2. If you are controlling your ship by lock throttle just lock it before accessing
  3. If you are flying manually pilot:mainthrottle is what you need (if I understand the documentation right)
Feinbube commented 9 years ago

So this behavior is intended? Your 2. suggestion is what I'm doing at the moment.

erendrake commented 9 years ago

It's not intended that you ever have to deal with a null without some safety check being available.

abenkovskii commented 9 years ago

I don't think it actually returns a null. It probably crashes while trying to get a special variable that is not set yet.

erendrake commented 9 years ago

@abenkovskii i was inarticulate before. If there is a chance that you will end up with a binding that might throw some nasty error at you. I like for there to be some way for you to ask if it is in a bad state.

This situation was something i ran into awhile ago but after squad made the baffling choice to start us out with 0.5 throttle on the pad i didnt see where we could assert a starting throttle without a more complex system then i was willing to add at the time.

Dunbaratu commented 8 years ago

closing as wontfix because @erendrake's comment makes it look like that was the intent.