Scripts / [BETA 1.006] Sound doesn't play correctly in entity script

Author
Message
tomjscott
User Banned
Posted: 8th May 2014 02:24
OS:- Windows 7 Home Premium 64-bit SP1

CPU:- AMD Phenom II X4 945, 3.0Ghz

RAM:- 8Gb DDR3

GFX Card:- 2048MB NVIDIA GeForce GT 640

FPSC-R Version:- Beta 1.006





Error Report:- When a proximity script triggers that has both a prompt and a sound action, the sound doesn't play after the prompt appears. It plays when the player backs away from the entity.



Is it repeatable? Yes.



If so, how? Place an object in the scene and attach a custom LUA script for the main script. Run the level and approach the object. When you are within range, the prompt appears on screen, but the sound does not play. Then back away from the object and the sound will play when the prompt disappears.





Scene Commander
Support Manager
16
Years of Service
User Offline
Joined: 3rd May 2008
Location:
Posted: 10th May 2014 08:52
I afraid We cannot take custom script issues as bugs. I must say your script looks fine, but I've not tested it. I will do if I get time later. I've moved this to scripting for the moment to see if anyone else can shed some light.



SC

i7-4770s 3.10ghz - Geforce GTX 650ti
J_C
17
Years of Service
User Offline
Joined: 9th Nov 2007
Location:
Posted: 10th May 2014 13:08
tomjscott@

Your code is continuously calling the Prompt command and the PlaySound0 command when you are standing within PlayerDist..

This is OK for the Prompt command ... but the PlaySound0 command will be

always being told to start the sound so never starts...

We need a new command IsSoundPlaying or something so we don't start the sound if it is already playing...



Or you could use a global variable something like this..



isPlaying = 0



function function_main(e)



PlayerDX = g_Entity[e]['x'] - g_PlayerPosX;

PlayerDY = g_Entity[e]['y'] - g_PlayerPosY;

PlayerDZ = g_Entity[e]['z'] - g_PlayerPosZ;

PlayerDist = math.sqrt(math.abs(PlayerDX*PlayerDX)+math.abs(PlayerDY*PlayerDY)+math.abs(PlayerDZ*PlayerDZ));

if PlayerDist < 160 then

Prompt("Say something here");

if isPlaying < 1

isPlaying = 1

PlaySound0(e);

end

else

isPlaying = 0

end

end



We reset the isPlaying = 0 when we are greater than PlayerDist from entity..



Have not tried this but hope it will help...
PM
tomjscott
User Banned
Posted: 10th May 2014 15:55
That might work and I'll give it a try, but the assumption is that the PlaySound0 function would do the "is sound playing" logic itself and not play the sound if it is already playing. At least that's how I've done it in my own game engines and seen it done in others as well. I agree though that that may not be the case here. However, I think my assumption has a flaw anyway in that the sound could end up starting over again after it's played if the player is still in range. I'll verify if your theory is correct and proceed from there. I have a few ideas.
tomjscott
User Banned
Posted: 10th May 2014 16:28
OK, that works. Thanks for the tip. Bad assumption on my part.
BarZaTTacKS
10
Years of Service
User Offline
Joined: 3rd Feb 2014
Location:
Posted: 12th May 2014 17:31
I love finding and reading these threads, it really helps open my mind to lua programming! Thanks!!
PM

Login to post a reply

Server time is: 2024-12-22 01:08:26
Your offset time is: 2024-12-22 01:08:26