Hi Juri
I did not try the volume code..
I only put your original code into the Health.lue script..
and when I walk away from the Health box entity the sound goes lower and lower
and finally sound disappears if I am long way off...
Also if you face the health box the sound is coming out of both left and right speakers..
if I then move left or right then the sound moves gradually to only the left or right speaker.
A true 3D sound....
I think I saw this also mentioned in Lee's blog a while back...
but your code was the first time I had any play with sound..
So I think your Volume code is not needed for varying sound volume by distance.
Juri I want to thank you for putting that code problem on the forum..
because I was also confused by the
local bksound = 0
When I first looked at your code I was saying to myself...
ok the bksound is local so it should be local to this entity..
so if I add another entity then it's bksound should be local to itself..
but as we found and as smallg has confirmed in his post
local bksound or any local variable is NOT local to the ENTITY it is local to the lua.file
so every entity we attach to the file the local variable ( bksound ) is really GLOBAL to all ATTACHED ENTITIES..
now this is a trap I am sure I would have fallen into at some point...
but your code was a good example to see this local variable behavior in a clear way that could be quickly seen.
I think also that my confusion was stimulated by the recent talks of the GLOBAL variables and sudden influx of LOCAL
variables in code samples...
if the code had been written as
bksound = 0;
or
global bksound = 0;
I would know immediately that the problem was all entities can see this bksound so can effect it..
now adding the
local bksound = 0;
confused my mind to think oh this is local only to this entity...
I know this effect will only be a problem in certain code situations ( like the usage in this sound code)
Thanks again Juri and smallg for alerting me to this...