Jump to content

Photo

Linking sound to a switch


  • Please log in to reply
16 replies to this topic

#1
Officer360

Officer360

    Newbie

  • Validating
  • Pip
  • 15 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.

#2
stevie70

stevie70

    Fan

  • Banned
  • PipPipPip
  • 484 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.

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, 30 June 2011 - 06:15 AM.


#3
Officer360

Officer360

    Newbie

  • Validating
  • Pip
  • 15 posts
thank you. i dont really understand script because i just started working with the geck but im sure i can figure it out. thank you for your help.

#4
Officer360

Officer360

    Newbie

  • Validating
  • Pip
  • 15 posts
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.

#5
stevie70

stevie70

    Fan

  • Banned
  • PipPipPip
  • 484 posts

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...?

#6
Officer360

Officer360

    Newbie

  • Validating
  • Pip
  • 15 posts
Scn KlaxonAlarm

begin OnActivate
if GetOpenState == 3
PlaySound QSTKlaxonA
SetOpenState 1
elseif GetOpenState == 1
SetOpenState 0
endif
end

im using the ElectricSwitch02

#7
stevie70

stevie70

    Fan

  • Banned
  • PipPipPip
  • 484 posts

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

#8
Officer360

Officer360

    Newbie

  • Validating
  • Pip
  • 15 posts
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.

#9
stevie70

stevie70

    Fan

  • Banned
  • PipPipPip
  • 484 posts

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...?

#10
Officer360

Officer360

    Newbie

  • Validating
  • Pip
  • 15 posts
ya ive plugged in different sound and they all do the same thing.




Page loaded in: 1.058 seconds