Scripts / Scripting help, multiple entities

Author
Message
Yurif74
GameGuru TGC Backer
10
Years of Service
User Offline
Joined: 1st Aug 2013
Location: italy
Posted: 5th Jun 2014 11:41 Edited at: 5th Jun 2014 11:43
Hello all,

i'm going crazy with a script i made.. i noticed it work perfectly if one entities is used, but if i place 2 or more entities then it stop working..



i taken a machinery entity and added "machinery.wav" into sound0 slot, then i writed this script:







don't take care of the volume code, it's not working..

problem is that if you use only one entity when you go far away (>200 units) sound stop working correctly

but if you place 2 entities then sound loop forever even if you run very far (>20000 units)

why? any clues?

thanks

Juri



Amiga 4000 CSMK1 68060@50mhz, 200mb fast, CV64 4mb, Scandoubler, MiniThylacine 4 port USB, FastAta MKVI 4000, DVD+RW, HDD 120gb pio 5.
J_C
16
Years of Service
User Offline
Joined: 9th Nov 2007
Location:
Posted: 5th Jun 2014 17:19 Edited at: 5th Jun 2014 17:31
Hi Juri

Very nice little problem..

I have not played with the sound before but this is interesting.

I used the Health script and the health box and added your code..

Yes the sound does not stop... but it is really cool the greater your Player distance from the health boxes

the lower the sound goes... also if you go left or right the sound moves between left and right speakers..nice..



back to your problem... I did get it to work...see my thoughts in the code rems...

I renamed a copy of [health.lua ] to [health_jc.lua] and added multiple health-box's to use this lua file.

Hope this helps...



PM
J_C
16
Years of Service
User Offline
Joined: 9th Nov 2007
Location:
Posted: 5th Jun 2014 17:23
dang! no code block..

How do you use the code block thingy...
I know I've used it before.. but I'm getting old..
can some one remind me...pretty please...
PM
The Next
TGC Web Engineer
16
Years of Service
User Offline
Joined: 3rd Dec 2007
Location: United Kingdom
Posted: 5th Jun 2014 17:31 Edited at: 5th Jun 2014 17:32
Fixed it,



You need to do it like this



[ code lang=lua]CODE HERE[ /code]



*Without the spaces after the [

Windows 7 Pro, Intel i7 3.8 GHz, 16GB DDR3, NVIDIA GTX 780 4GB Superclocked
PM
J_C
16
Years of Service
User Offline
Joined: 9th Nov 2007
Location:
Posted: 5th Jun 2014 18:17
Cheers The Next - thanks... that's very quick service..
I'm going to write this down..
I don't want to prove I'm senile by forgetting again.

PM
J_C
16
Years of Service
User Offline
Joined: 9th Nov 2007
Location:
Posted: 5th Jun 2014 18:41
Sorry Juri - for my bad memory hi-jacking most of your thread...

The Next as we are on the topic of code blocks...
I noticed in my script block that the rem-block at the end is not showing the code as green rem code..?
The old health.lua code

--[[
old health_main code
--]]
PM
smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 5th Jun 2014 19:37
if the volume is automatic i dont think you need most of that code - especially as i see no offset for vol anyway (vol = vol + 1 / vol = vol - 1 should be in there somewhere to control the volume level)?

and yh the issue is that backsound would be set to 0 all the time as you would always be out of range of 1 of the entities (so long as they are far away from eachother anyway - which i assume would be the point in having the script twice)
but j_c fixed that by adding more backsound variables

life's one big game

windows vista ultimate

i5 @3.3ghz, 4gb ram, geforce gtx460, directx 11
Yurif74
GameGuru TGC Backer
10
Years of Service
User Offline
Joined: 1st Aug 2013
Location: italy
Posted: 6th Jun 2014 16:08
this line control the volume


however the volume function doesn't work, at least for me, you can set it any values (1,10,100) the volume is at maximum bit if i set to 0 then volume is 0..

@J_C: the volume code is it working for you? that's very strange!!! i can't get it to work! thanks for the code, i will try in the weekend

Juri



Amiga 4000 CSMK1 68060@50mhz, 200mb fast, CV64 4mb, Scandoubler, MiniThylacine 4 port USB, FastAta MKVI 4000, DVD+RW, HDD 120gb pio 5.
smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 6th Jun 2014 17:27
wow yh i completely missed that line, sorry

so i just tested the script for volume change and it does work - however i feel the change in volume is actually pretty high -> 70 is very quiet already so if it's not working for you i would suggest changing the line
to something like
just to test

life's one big game

windows vista ultimate

i5 @3.3ghz, 4gb ram, geforce gtx460, directx 11
J_C
16
Years of Service
User Offline
Joined: 9th Nov 2007
Location:
Posted: 6th Jun 2014 17:46
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...
PM
Avram
GameGuru TGC Backer
17
Years of Service
User Offline
Joined: 3rd Sep 2006
Location: Serbia
Posted: 6th Jun 2014 19:00
Haven't tried, but try to set volume between 0 and 1... so 0.3 would be 30% and 0.5 50%, while 1 is 100%, of course it usually goes like that in some other programming languages, so why not in LUA too?

smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 6th Jun 2014 20:49 Edited at: 6th Jun 2014 21:02
strangely if i didn't include the setvolume command it didnt make any difference for me (certainly not noticable at least, maybe i needed to be far away to notice any change) but with the set volume command in place it did change



and i definitely think it's 0 ~ 100, not 0 ~ 1, 70 was definitely quieter than 100 which wouldnt have been true if max was 1.

ok just checked, volume must be between 0 and 100 otherwise it'll error out.



yh it does seem a bit odd that it would kinda ignore the "local" but i think, as u say, it only happens when the script is 'repeated' on different entities - if you simply copy and rename the original script and place it on the second entity it will also work

life's one big game

windows vista ultimate

i5 @3.3ghz, 4gb ram, geforce gtx460, directx 11
Yurif74
GameGuru TGC Backer
10
Years of Service
User Offline
Joined: 1st Aug 2013
Location: italy
Posted: 7th Jun 2014 14:26
now it's very crazy!
i tried modifications made by J_C and it work..

problem is i still get 100% of volume, i tried to increase range to 1000 but sound is not 3D for me.. and i don't know why!



Amiga 4000 CSMK1 68060@50mhz, 200mb fast, CV64 4mb, Scandoubler, MiniThylacine 4 port USB, FastAta MKVI 4000, DVD+RW, HDD 120gb pio 5.
Yurif74
GameGuru TGC Backer
10
Years of Service
User Offline
Joined: 1st Aug 2013
Location: italy
Posted: 7th Jun 2014 14:44 Edited at: 7th Jun 2014 15:20
nothing to do... this code is useless for me.. try to place 20 entities and run the level: fpsc:r reload previous session without any error.. maybe a bug of fpsc:r?



EDIT: it does appear that my script does suffer the MAX 18 ENTITIES bug! (like placing more than 18 ammo box)



Amiga 4000 CSMK1 68060@50mhz, 200mb fast, CV64 4mb, Scandoubler, MiniThylacine 4 port USB, FastAta MKVI 4000, DVD+RW, HDD 120gb pio 5.
tomjscott
User Banned
Posted: 7th Jun 2014 19:16
You can simplify some of the script by adding the following before your main function:



Then you can eliminate the nil checks everywhere.

System Specs: 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.007
J_C
16
Years of Service
User Offline
Joined: 9th Nov 2007
Location:
Posted: 8th Jun 2014 13:19
Juri the 3D sound effect is only present in your original non working code.
When you have more than one entity and the sound remains ON then when you walk around you get the 3D sound effect..
PM

Login to post a reply

Server time is: 2024-04-25 13:12:04
Your offset time is: 2024-04-25 13:12:04