ayser 1 Posted August 8, 2012 So, I have a car, and I want it to play a sound. I got that part down, it plays the music it's supposed too, but I want to do it when the player chooses to play the music. When The player does "Toggle" (From the added action to the car), it will start the music. If the music is already playing, it'll hint "A song is already playing". This bit of code isn't working for me, and i'm not sure why. Any idea? Did I do something wrong? _object = _this select 0; _toggle = 0; while { alive _object } do { if ( _toggle == 1) then { hint "A song is already playing"; }; if ( _toggle == 0 && _toggle != 1) then { _object say3D "Qom_Nasheed"; _toggle = 1; //sleep 90; //_toggle = 0; }; }; Share this post Link to post Share on other sites
kylania 568 Posted August 8, 2012 Use the condition field of the addAction to prevent the option even showing up if it's playing. Share this post Link to post Share on other sites
ayser 1 Posted August 8, 2012 Use the condition field of the addAction to prevent the option even showing up if it's playing. I tried this this addaction ["Song", "Scripts\Qom_Nasheed.sqf", (hideOnUse)]; Didn't work, even tried without ()'s. I've edited the .sqf and changed it to this _object = _this select 0; _toggle = 0; while { alive _object} do { _object say3D "Qom_Nasheed"; //_toggle = 1; _object removeAction 0; Sleep 5; _object addaction ["Song", "Scripts\Qom_Nasheed.sqf"]; hint "1"; }; Does the job fine, and removes the action, but i'm kinda stumped. I click song, it disappears for 5 seconds like I want it to, and comes back in 5 seconds. But when I click Song again, it wont dissapear and can be selected infinite times. Share this post Link to post Share on other sites
kylania 568 Posted August 8, 2012 Erm, close. _object addAction ["Play Song","scripts\Qom_Nasheed.sqf",[],1,false,true,"","!songPlaying"]; Then just have your script set songPlaying to true while playing and reset it when done. Make sure it's a global variable though. Might need to publicVariable and CBA globalExecute if it's multiplayer. :) Share this post Link to post Share on other sites
ayser 1 Posted August 8, 2012 (edited) http://gyazo.com/3286cdb24a0f09eb050fea1e98dddcca.png?1344402599 (229 kB) _object = _this select 0; _toggle = 0; while { alive _object} do { _object say3D "Qom_Nasheed"; songPlaying = True; //_toggle = 1; //_object removeAction 0; Sleep 5; //_object addaction ["Song", "Scripts\Qom_Nasheed.sqf"]; hint "1"; }; The "Play Song" option doesn't appear at all, probably since I didn't do the "set songPlaying to true" correctly. Is it set songPlaying = true;, or what? Sorry, i'm still fairly noobie to scripting :P Edit: Tried these too, didn't work _object setVariable ["songPlaying", true]; _object setsongPlaying True; _object songPlaying True; Also tried putting this in my init, didn't work songPlaying = true; publicVariable "songPlaying"; Edited August 8, 2012 by ayser Share this post Link to post Share on other sites
ayser 1 Posted August 8, 2012 Bump, still need help :( Share this post Link to post Share on other sites
kylania 568 Posted August 8, 2012 (edited) You're setting songPlaying to true in the init, but the action is set to only appear when the song is NOT playing. :) (The ! symbol means "not".) That's why you're not seeing it. Here's a demo. Edited August 8, 2012 by kylania Share this post Link to post Share on other sites
ayser 1 Posted August 8, 2012 (edited) You're setting songPlaying to true in the init, but the action is set to only appear when the song is NOT playing. :) (The ! symbol means "not".) That's why you're not seeing it. Doh! Shoulda tried that. It shows up and disappears now when I select it, but 5 seconds after it doesn't pop back up, just re-plays the song. Not sure what i'm doing wrong... So used to java scripting, and this is like a smack in the face _object = _this select 0; _toggle = 0; while { alive _object} do { _object say3D "Qom_Nasheed"; songPlaying = true; Sleep 5; songPlaying = false; hint "1"; }; Shouldn't it do the following: Song starts playing Sets songPlaying to true Waits 5 seconds Sets songPlaying to false (Making the "Play Song" option re-appear) What it does: Song starts playing Sets songPlaying to true Waits 5 seconds Song starts playing ----------------------------------------------------------- Edit: Got it working now :) _object = _this select 0; _toggle = 0; while { alive _object && _toggle == 0} do { _object say3D "Qom_Nasheed"; _toggle = 1; hint "Now playing Qom Nasheed"; songPlaying = true; Sleep 90; songPlaying = false; }; _toggle = 0; Edited August 8, 2012 by ayser Share this post Link to post Share on other sites
kylania 568 Posted August 8, 2012 Got it working now Congrats! :) Share this post Link to post Share on other sites