Quirky Sound Object Behavior
Zephirius
Member Posts: 419
I think the problem might lie in my code, so I'll post this right here.
I have through a conversation node, a script to activate a sound object. The sound object is set to "Play Once", yet it appears to fire off at random intervals, totally breaking the intended immersion of the unfolding scene.
The sound object initially fires once, plays and ends smoothly. The problem lies when you exit the map and return. When you do the sound object seemingly fires randomly. The truth is I don't know if the return has anything to do with the sound object playing again.
I just know the sound object is set to play once and is activated by code. It plays as scripted, but afterwards, seems to play randomly.
code -
Thanks for any insights you might have...
I have through a conversation node, a script to activate a sound object. The sound object is set to "Play Once", yet it appears to fire off at random intervals, totally breaking the intended immersion of the unfolding scene.
The sound object initially fires once, plays and ends smoothly. The problem lies when you exit the map and return. When you do the sound object seemingly fires randomly. The truth is I don't know if the return has anything to do with the sound object playing again.
I just know the sound object is set to play once and is activated by code. It plays as scripted, but afterwards, seems to play randomly.
code -
#include "x3_inc_string" void main() { object oPC = GetPCSpeaker(); DestroyObject(GetObjectByTag("TOMB_BLOCK"), 0.0); if ( GetLocalInt(oPC, "DO_ONCE__" + GetTag(OBJECT_SELF)) ) return; SetLocalInt(oPC, "DO_ONCE__" + GetTag(OBJECT_SELF), TRUE); location lLoc = GetLocation(oPC); location lLoc2 = GetLocation(GetWaypointByTag("SHAD_LOC")); DelayCommand(2.0, AssignCommand(OBJECT_SELF, ActionForceMoveToLocation(lLoc2, TRUE, 30.0))); DestroyObject(OBJECT_SELF, 6.0); // Declare string variables. string sTalk = "Music by Ronnie James Dio."; string sRGB = StringToRGBString(sTalk, STRING_COLOR_GREEN); DelayCommand(0.5, FloatingTextStringOnCreature(sRGB, oPC)); DelayCommand(0.5, SoundObjectPlay(GetObjectByTag("DIO_01"))); }
Thanks for any insights you might have...
Post edited by Zephirius on
0
Comments
So long as whatever the script is running on (the conversation object) still exists at the end of the delay, the sound object should be turned off positively after playing once and not play again.
Another possibility is that this script is being called from something you didn't expect to call it from, such as the OnPerception event of an NPC.
And then again, in multi-player it would be entirely possible for this whole start-stop thing to be messed up by one player aborting the conversation and another starting it before the sound object had finished playing.
In fact, if I remember correctly there's a conversation option known as "other actions" which might be able to do what you want, with a bit of playing around.
You could also use the AssignCommand command to make a nearby non-static invisible object play the sound, so that the conversation owner doesn't have to take time out to play the sound.
I've tried using PlaySound before with mixed results. Indeed, it does work.
The problem lies with the localization of the sound being called. By moving the PC further away from the initial location where the sound was first called, the sound will inevitably become fainter until finally disappearing altogether. That's why I'm using SoundObjectPlay, for the "plays area wide" option that it gives you.
In that case, perhaps you need to use my first suggestion which is use DelayCommand to shut off the sound object after playing once. That way, it can't be retriggered until the conversation is used again.
For a backstop, I'd probably also set up a do-once variable to stop that conversation branch from being selected again until after the sound has stopped, and I'd have another DelayCommand to remove that variable to re-enable it.
That is, unless the sound is intended to be truly play-once-only and can never be retriggered.
You have to call SoundObjectStop on it after SoundObjectPlay. Use DelayCommand to get it to turn off at the right time.