Hi,
Both those functions are useful for waiting in a script.
Is there any reason I should use one instead of the other (eg : savegame stability or whatsoever) ?
I use those functions to monitor every second if an event is supposed to happen.
Red
Hi,
Both those functions are useful for waiting in a script.
Is there any reason I should use one instead of the other (eg : savegame stability or whatsoever) ?
I use those functions to monitor every second if an event is supposed to happen.
Red
"Wait" literally waits. Nothing in the Script after it will run until that period of time has expired.
"RegisterForSingleUpdate" will run everything after it in the Script (as appropriate), and then add the Script into the 'Queue' to be run again in the future.
Each of them has a use, and they're not always interchangeable; depending how your Script is set up, and what you want to do, one might be better than the other. For example, in one of my Scripts I play an IMOD, then use Wait(10.0) so that the first-half of the IMOD plays out before I make changes to the Player. On the other hand, another Script I have is constantly monitoring the Player's Health, and so uses 'SingleUpdate(1.0) to run the whole script every second.
What is it you're doing? Generally you should not be running a Script every second--there are times when you'll need to do that, but for the most part it should be avoided.
I use a script that monitors the distance between a NPC and the player.
Once the conditions are met, it starts a scene.
Presently the monitoring is done with RegisterForSingleUpdate(), while the scene starting is done with Wait(), because it has for example to wait for a discussion to be over before starting the scene.
I was just wondering if those functions could cause some harm
From what you describe, it sounds OK to me--maybe someone else will have another comment, but that sounds like how I'd do it--use RFSU to start the scene, then Wait to hold the script until it's played. I've not worked much with dialogue/scenes, so you might be able to advance the script with a ScriptFragment on the dialogue/scene itself, but I'll leave that to someone else
RegisterForSingleUpdate has the advantage of being able to update the script/functions, unlike a utility.wait loop. In the example below, if you run SomeFunction() and for some reason Bob can never get close enough to Susan, modifying the SomeFunction() function will do nothing and you'll be stuck in an infinite loop. However, if you run the OnUpdate() (you can call it directly like a function if you want), you can update the OnUpdate() function and the updated version will be run the next time OnUpdate() is called.
Actor Bob
Actor Susan
float fMinDist
float fUpdateTime
Function SomeFunction()
while Bob.GetDistance(Susan) > fMinDist
Utility.Wait(fUpdateTime)
endWhile
;do stuff
endFunction
Event OnUpdate()
if Bob.GetDistance(Susan) > fMinDist
RegisterForSingleUpdate(fUpdateTime)
else
;do stuff
endIf
endEvent
A utility.wait will also keep the script active unlike a registerforsingleupdate, so it would typically be beneficial to register for update for long running waits for performance reasons.