Jump to content

Scripting - Waiting for TranslateTo to complete


Recommended Posts

I'm manipulating references from a script with TranslateTo, but i'd need the script to wait for the translation to be completed before running the next line of code so that everything happens in order. I'm aware of OnTranslationAlmostComplete event but since it's received by the reference being moved and not the script doing the moving i'm not sure how i'd use it.

 

My current idea is:

Ref.TranslateTo(Target.X, Target.Y, Target.Z, Target.GetAngleX(), Target.GetAngleY(), Target.GetAngleZ(), 50.0)
Wait(sqrt(pow(Target.X - Ref.X) + pow(Target.Y - Ref.Y)) / 50.0) ; distance/speed = time
; continue doing stuff.

But it requires some calculations and i'm not sure how reliable it would be, if the game is lagged or whatever...

 

Any better ideas?

 

Edit: i'm moving on a plane, that's why i ignore Z on distance calculation.

Edited by FrankFamily
Link to comment
Share on other sites

There is SKSE's ModEvent functions. You might be able to make a custom event that is triggered by the OnTranslationAlmostComplete event rather than going bonkers with math for a Wait function.

 

Don't ask how it works as I've never used it, but I have seen it at work before in other mods...

Link to comment
Share on other sites

Thanks, i'll look into that.

 

In the meantime i thought about a workaround, if the script will pause waiting for the external function call to return then it should work, right?

Ref.TranslateTo(...)
(Ref as RefScript).WaitForCompletion()
;continue doing stuff

---------------------
Scriptname RefScript Extends ObjectRef

Function WaitForCompletion()
GoToState("Translating")
While GetState() == "Translating"
Wait(1.0)
EndWhile
Return
EndFunction


State Translating

Event OnTranslationAlmostComplete()
GoToState("")
EndEvent

Event OnTranslationFailed() ; for safety reasons
GoToState("")
EndEvent

EndState
Edited by FrankFamily
Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...