KSP-KOS / KOS

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

TARGET can get forcibly changed by the game itself between IPU ticks #2435

Open Dunbaratu opened 5 years ago

Dunbaratu commented 5 years ago

Rather than try to fight KSP about this, I'd rather just document that it happens. I'm tired of fighting KSP on this one.

The situation where the problem happens is this:

(1) Although your ship is close enough to another vessel for it to be loaded and unpacked, Your ship is still not close enough for the stock game to allow you to manually select a docking port as target on that ship. (This happens if your ship is > 200m away from the other vessel - at this distance the user interface lets you target the vessel as a whole by clicking it with the mouse, but does not let you target its docking port parts by clicking the mouse).

(2) Your script executes SET TARGET TO OTHERSHIP:PARTSTAGGED("The Docking Port")[0]. to try to target that docking port that the stock game wouldn't allow you to from this distance.

(3) Although this wouldn't work via manual mouse clicking, through the script kOS allows it to work. Your target is set to the docking port now. But only very temporarily (see (4) below).

(4) The next time your script is done with one IPU's worth of program, and pauses to continue on the next physics tick, the main KSP game's UI checking takes over, notices "hey my target is set to a part but I'm too far away for that, so I'll switch target to that part's vessel instead of the part."

(5) The script, which just got done setting TARGET to the docking port, doesn't know that the main game usurped control and moved TARGET to the vessel instead. Now it tries to call a suffix like PORTFACING and gets an error because kOS says TARGET is of type vessel. The user is very confused.

Dunbaratu commented 5 years ago

There is a chance this problem was introduced because of the fix to mapview rotation in PR #2403. For some unkonwn reason, KSP rotates the map view when the input lock for setting target is unlocked. Fixing the mapview rotation bug meant having to mask off the set target input lock when focusing on the terminal window. That may be affecting this issue. But if I have to choose between fixing the mapview rotation bug and fixing this target usurping bug and KSP refuses to allow me to fix both, then I'd rather the mapview rotation bug be the one that stays fixed.