Jump to content

Linking sound to a switch


Officer360

Recommended Posts

i haven't found anything on here about this or anything at all on the web.

im making my own vault with a security room and i want to have a switch in that room the flips on an alarm and some Klaxon

lights ive placed around the vault

what im trying to do is link the klaxon alarm sound so that when i activate the switch to turn the klaxon light on the siren

comes on as well. so far i cant seem to link the two correctly. because of this i also cant link the vault emergency light to it

either. so in short when i flip a switch the alarm light will spin but the sound with either be playing before i even have touched the switch or wont play at all and the light will not turn on and off with the switch as well. any help would be really great.

Link to comment
Share on other sites

i haven't found anything on here about this or anything at all on the web.

im making my own vault with a security room and i want to have a switch in that room the flips on an alarm and some Klaxon

lights ive placed around the vault

what im trying to do is link the klaxon alarm sound so that when i activate the switch to turn the klaxon light on the siren

comes on as well. so far i cant seem to link the two correctly. because of this i also cant link the vault emergency light to it

either. so in short when i flip a switch the alarm light will spin but the sound with either be playing before i even have touched the switch or wont play at all and the light will not turn on and off with the switch as well. any help would be really great.

you'd just need

begin OnActivate
    PlaySound soundname
end

to make it play whenever you activate the switch.

or, if the sound is an ogg-file, this would be

PlaySound3D soundname

(in some cases, i couldn't get this to play either though, maybe someone else knows about that)

 

or, if you have a switch with an on/off-animation, and just want it to play when you turn it on

begin OnActivate
    if GetOpenState == 3                      ; if switch is off
         PlaySound soundname              ;      play sound
         setopenstate 1                           ;      set switch to on (GetOpenState returns different values than SetOpenState uses)
    elseif GetOpenState == 1               ; if switch is on
         setopenstate 0                          ;      set switch to off
    endif
end

 

and turning the light on/off would mostly mean having two copies of the same light in the same place, one on and one off, and always enabling the one you need and disabling the other one, there's various ways to do that, for example either with making one of the lights the switches linked ref and the other lights enabling parent (opposite), you'd then switch that on by

ref LightMaster

begin OnActivate
    set LightMaster to GetLinkedRef        ; sets your light-variable to the linked reference
    Lightmaster.enable 0                          ; and enables it (and light 2, if enable child/opposite disappears at same time) 
end

 

or by making both of the lights persistant, giving them a name like lightOnREF and adding like

    lightOnREF.enable 0             ; makes on-light appear
    lightOffREF.disable 0            ; and off-light disappear - the 0 makes it pop in/out instead of fade

(and the other way around for turning off) to the above script (right where the setopenstate's are)

Edited by stevie70
Link to comment
Share on other sites

ok i tried the script for the sound with an on off switch but my problem now is that after hitting the switch to turn the sound on if i hit it again to turn it off it just plays the sound again.
Link to comment
Share on other sites

ok i tried the script for the sound with an on off switch but my problem now is that after hitting the switch to turn the sound on if i hit it again to turn it off it just plays the sound again.

if you used the one that checks for the switches open state plus a switch that actually has and on/off animation state (check in preview window), i don't really see how this could be happening - could you please post the whole script you used 2 have a look at it...?

Link to comment
Share on other sites

Scn KlaxonAlarm

 

begin OnActivate

if GetOpenState == 3

PlaySound QSTKlaxonA

SetOpenState 1

elseif GetOpenState == 1

SetOpenState 0

endif

end

 

im using the ElectricSwitch02

Link to comment
Share on other sites

Scn KlaxonAlarm

 

begin OnActivate

if GetOpenState == 3

PlaySound QSTKlaxonA

SetOpenState 1

elseif GetOpenState == 1

SetOpenState 0

endif

end

 

im using the ElectricSwitch02

hm, i don't see anything wrong with that - is the switch animation going where it should when you switch?

and if so, and are you sure the sound plays AGAIN when you switch it off and not just KEEPS playing...? maybe the sound you picked just continues looping, if so, just make a non-looping copy and play that

Link to comment
Share on other sites

the sound was playing over again when i switch it off and then back on, the sound would play again over-top of the sound but i did what you said and created a file where the sound doesn't loop and now the sound wont play at all when i flip the switch.
Link to comment
Share on other sites

the sound was playing over again when i switch it off and then back on, the sound would play again over-top of the sound but i did what you said and created a file where the sound doesn't loop and now the sound wont play at all when i flip the switch.

sorry 4 late response, work... :-P

if you haven't solved that anyway meanwhile - have you tested the whole thing with a different sound (one that's definitely a one shot...?

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...