gpp9999 Posted March 24 Share Posted March 24 Hi, I'm looking at an old mod that allows playing instruments by playing a sound when you press a key on the keyboard. It has pieces of code that looks like this: Spoiler Int Property iHotkeyA = 30 Auto Sound Property A Auto ; .... later, in an OnEquipped event .... while (!Input.IsKeyPressed(iHotkeySpace)) RegisterForSingleUpdate(0.001) if ( Input.IsKeyPressed(iHotkeyA) ) instanceID = A.Play(ak) Sound.SetInstanceVolume(instanceID, 1.0) while ( Input.IsKeyPressed(iHotkeyA) ) RegisterForSingleUpdate(0.001) endwhile Sound.SetInstanceVolume(instanceID, 0.8) Utility.wait(0.0001) Sound.SetInstanceVolume(instanceID, 0.6) Utility.wait(0.0001) Sound.SetInstanceVolume(instanceID, 0.4) Utility.wait(0.0001) Sound.SetInstanceVolume(instanceID, 0.2) Utility.wait(0.0001) StopInstance(instanceID) endif I'm new to papyrus scripting, but my understanding of RegisterForSingleUpdate is that it will cause the OnUpdate event to be called after the specified time. However this script has no OnUpdate event. I was also getting errors in the log coming from the RegisterForSingleUpdate calls ("Object reference has no 3D" and "no native object bound to the script object, or object is of incorrect type"). I tried commenting out all of the calls and the mod still works fine as far as I can tell. So I'm wondering if there's any reason to have those in there. Trying to understand why the original mod author might have done it this way. Link to comment Share on other sites More sharing options...
xkkmEl Posted March 24 Share Posted March 24 I easily could be wrong, but my understanding is the same as yours. The only case I can see this doing something is if the script "extends" another, and the inherited script does catch the OnUpdate event. Link to comment Share on other sites More sharing options...
IsharaMeradin Posted March 25 Share Posted March 25 The update registrations apply to the object itself. This means that any script attached to the object will be able to receive the OnUpdate event. It may be possible that the mod in question was designed to interact with something else. It may be possible that there was an OnUpdate event at one point that has since been removed and the registrations forgotten about. It is also possible that they were copied from an example without understanding what it was meant to do. Who knows at this point. If the mod works without them, no need to include them. FYI - pretty sure that the OnKeyUp event would be better than using a while loop with IsKeyPressed. Use OnKeyDown to start playing, then OnKeyUp to end playing. Link to comment Share on other sites More sharing options...
Recommended Posts