Closed PhilouDS closed 6 months ago
Yes, warp_to has recently changed to async because I had noticed some very strange behavior when using it without properly surrounding it with a yield
in certain situations (i.e. wait for a FixedUpdate to happen).
But I can see your use-case and triggering a warp in a UI callback most like will not cause any problem.
As a quick-fix I added a sync_warp_to
function to ksp::game::warp
with the previous functionality in this pre-release:
https://github.com/untoldwind/KontrolSystem2/releases/tag/v0.5.5.1
... I guess the proper way to fix this would be to allow for async lambda functions, which I tried to avoid so far.
I tried this and it worked fine.
Could I write my scrip differently so I can continue to use warp_to
instead of sync_warp_to
? I have no problem to use sync_warp_to
, it's just to understand.
(btw, the last vsix extension (0.0.27) for visual studio is great too)
Just a thing about the vsix extension. I have this "error" message with the use of format
.
The vsix extension (or rather the underlying lsp-server) still has some issues with generics, I made a small tweak so that at least no error is shown if the concrete type is still in question.
Concerning the warp_to
: As a rule of thumb, use warp_to
whenever possible unless there is this sync context error (e.g. inside at button callback).
Unluckily the underlying problem is quite complicated.
In the unity engine every component might have an Update
or FixedUpdate
method which is called either on every frame refresh or as often as possible. In KSP2 these are used to do a lot of calculations and internal updates.
For the scripting part the problem boils down to: How many changes can you make to the internal game state inbetween those update cycles without the entire state getting wonky. E.g. changing a maneuver node and triggering a warp_to in the same cycle has created some pretty unpredictable results, therefore the change.
So the new warp_to
will do:
FixedUpdate
TimeWarp
classFixedUpdate
just to be saveUnluckily this currently only works, when the script is in an async context (like in the fn main_flight
function). Inside a button callback this is not so easy, because it is an UI event listener and "Waiting for the next FixedUpdate" would most likely freeze the UI.
I am still not sure about the best solution for this, eventually though there should be only one warp_to
function that works in both cases.
In 0.5.5.3 https://github.com/untoldwind/KontrolSystem2/releases/tag/v0.5.5.3
the two version of war_to
should be merge again, i.e. there is just one warp_to
that can be use in sync and async (under the hood there are still two functions that are picked based on the context ... in short it is the task of the compiler to worry about what version to use).
Nice 👍
This issue is stale because it has been open for 60 days with no activity.
This issue was closed because it has been inactive for 14 days since being marked as stale.
I have an error message with my script below used in the VAB. I use it inside the
.on_click
method of my warp button. It's the first time I see this error. Is it caused by the last released version (0.5.4.1)?This is my script. I have a comment line just before the problem