ginger_buddy Posted February 14, 2015 Share Posted February 14, 2015 is it possible to use command handler to change a variable in a particular script? For example (in sound.script) SoundEnabled = true function sound() if SoundEnabled then [some code] end AddEventHandler(......) now this function is my disable and enable sound function: function disablePlayLocalMusic(playerSource) if (playerSource) then if(SoundEnabled) then SoundEnabled = false outputChatBox ( "Ambience Sounds Disabled!", playerSource ) end elseif not (GroveEnable) then outputChatBox ( "Ambience Sounds Already Disabled!", playerSource ) end end end addCommandHandler ( "OffAmbience", disablePlayLocalMusic) function enablePlayLocalMusic(playerSource) if (playerSource) then if(SoundEnabled) then outputChatBox ( "Ambience Sounds Already Enabled!", playerSource ) end elseif not (SoundEnabled) then SoundEnabled= true outputChatBox ( "Ambience Sounds Enabled!", playerSource ) end end end addCommandHandler ( "OnAmbience", enablePlayLocalMusic) I want to use them to change soundEnabled to either true or false However in the game when I typed /OnAmbience or /OffAmbience, nothing happens and the function sound() also stops working. What did I do wrong? or does this method even work? Link to comment
Enargy, Posted February 14, 2015 Share Posted February 14, 2015 try this: local SoundEnabled = false function disablePlayLocalMusic(playerSource, command) if (playerSource) then if(SoundEnabled) then SoundEnabled = false outputChatBox ( "Ambience Sounds Disabled!", playerSource ) elseif not (SoundEnabled) then outputChatBox ( "Ambience Sounds Already Disabled!", playerSource ) end end end addCommandHandler ( "OffAmbience", disablePlayLocalMusic) function enablePlayLocalMusic(playerSource, command) if (playerSource) then if(SoundEnabled) then outputChatBox ( "Ambience Sounds Already Enabled!", playerSource ) elseif not (SoundEnabled) then SoundEnabled= true outputChatBox ( "Ambience Sounds Enabled!", playerSource ) end end end addCommandHandler ( "OnAmbience", enablePlayLocalMusic) PD: Where is function sound() exactly? Link to comment
ginger_buddy Posted February 14, 2015 Author Share Posted February 14, 2015 Thank you Very much. The Sound() function (written above the disable and enable function in the same script file) just plays random music from music table at player location every once awhile. It appears that my original disable and enable function has incorrect syntax, now the function name links to the 'end'. Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now