mat10193 13 Posted October 30, 2017 Hello, I am looking to create a script that will execute an action at a certain time each day, not just on one day. Share this post Link to post Share on other sites
HazJ 1288 Posted October 30, 2017 Something like this maybe? waitUntil { waitUntil {sleep 1; (daytime isEqualTo X)}; sleep X; false; }; You'll need to change the two X values, obviously. This will loop, it'll wait for first time to trigger then loop X hours later. I checked for some time event but couldn't find anything, wonder how Bohemia did it with the clock sound every hour. https://community.bistudio.com/wiki/daytime Not tested. Share this post Link to post Share on other sites
mat10193 13 Posted October 30, 2017 ok, i am assuming this would only work for only one task, how would i do this for multiple tasks at multiple different times a day. Sorry for not being specific before. Share this post Link to post Share on other sites
HazJ 1288 Posted October 30, 2017 Depends. What do you want to do for each task exactly? Can you provide a bit more info so I can help you better? Share this post Link to post Share on other sites
mat10193 13 Posted October 30, 2017 yeah sorry, i want a sounds to play at certain times over loudspeakers. i am concerned, however, that if i just tell it to play at, say noon, that it will only do it once and then the script will terminate and not go back to the start. Share this post Link to post Share on other sites
HazJ 1288 Posted October 30, 2017 It won't because it always return false. false; https://community.bistudio.com/wiki/waitUntil Share this post Link to post Share on other sites
mat10193 13 Posted October 30, 2017 EDIT thanks, so false tells it to not terminate Share this post Link to post Share on other sites
mat10193 13 Posted October 31, 2017 Spoiler while {true} do { // first call waituntil {daytime isEqualTo 5.83}; playSound3D ["bugle\sfx\first call.ogg", speaker1]; // reveille waituntil {daytime isEqualTo 6}; playSound3D ["Bugle\sfx\reveille.ogg", "speaker1"]; // assembly waituntil {daytime isEqualTo 7.92}; playSound3D ["Bugle\sfx\assembly.ogg", "speaker1"]; // morning colors waituntil {daytime isEqualTo 8}; playSound3D ["Bugle\sfx\morning colors.ogg", "speaker1"]; sleep 1; // mess call playSound3D ["Bugle\sfx\mess call.ogg", "speaker1"]; // assembly waituntil {daytime isEqualTo 11.92}; playSound3D ["Bugle\sfx\assembly.ogg", "speaker1"]; // mess call(noon) waituntil {daytime isEqualTo 12}; playSound3D ["Bugle\sfx\mess call.ogg", "speaker1"]; // first call waituntil {daytime isEqualTo 16.83}; playSound3D ["Bugle\sfx\first call.ogg", "speaker1"]; // evening colors waituntil {daytime isEqualTo 17}; playSound3D ["Bugle\sfx\evening colors.ogg", "speaker1"]; sleep 1; // mess call(evening) playSound3D ["Bugle\sfx\mess call.ogg", "speaker1"]; // tattoo waituntil {daytime isEqualTo 20.4}; playSound3D ["Bugle\sfx\tattoo.ogg", "speaker1"]; // call to quarters waituntil {daytime isEqualTo 20.83}; playSound3D ["Bugle\sfx\call to quarters.ogg", "speaker1"]; // taps waituntil {daytime isEqualTo 21}; playSound3D ["Bugle\sfx\taps.ogg", "speaker1"]; }; this is what i have, but it is not doing anything I think i realize what i did wrong Share this post Link to post Share on other sites
HazJ 1288 Posted October 31, 2017 You got it working now? Share this post Link to post Share on other sites
mat10193 13 Posted October 31, 2017 nope, this is what i have in my script and it is giving me an access violation error and my arma CTD's the previous spoiler did nothing, so i have been trying a few different things and this is what i have right now: Spoiler while {true} do { if (daytime > 5.82 && daytime < 5.87) then { execVM "test.sqf"}; if (daytime > 6 && daytime < 6.05) then { execVM "test.sqf"}; if (daytime > 7.83 && daytime < 7.88) then { execVM "test.sqf"}; if (daytime > 8 && daytime < 5.89) then { execVM "test.sqf"; sleep 1; execVM "test.sqf"}; if (daytime > 11.85 && daytime < 11.90) then { execVM "test.sqf"}; if (daytime > 12 && daytime < 12.05) then { execVM "test.sqf"}; if (daytime > 16.83 && daytime < 16.88) then { execVM "test.sqf"}; if (daytime > 17 && daytime < 17.05) then { execVM "test.sqf"; sleep 1; execVM "test.sqf"; }; if (daytime > 20.4 && daytime <20.45) then { execVM "test.sqf"}; if (daytime > 20.83 && daytime < 20.88) then { execVM "test.sqf"}; if (daytime > 21 && daytime <21.05) then { execVM "test.sqf"}; }; i was testing to see if the playsound3d was causing the CTD, so in the test. i have: Spoiler hint format ["Hello %1",player ]; and the daytime thing seems to work, but it spams the hint in the time range i have set up. Share this post Link to post Share on other sites
HazJ 1288 Posted October 31, 2017 Close some of the if statements. Add a sleep at the end of the whie-loop. Share this post Link to post Share on other sites
mat10193 13 Posted November 2, 2017 what do you mean by closing some of the if statements Share this post Link to post Share on other sites
HazJ 1288 Posted November 2, 2017 Oh, my bad. I didn't see your }; at the end as I do it on multiple lines. Easier to read! if () then { }; if () then { } else { }; Try adding "sleep 1;" before you close your while-loop block. Your current sleep in inside an if statement which will only trigger if the cond is true. Also, add a hintSilent debug message after execVM or inside the test.sqf file to see if it's triggering. EDIT: while {true} do { if (daytime > 5.82 && daytime < 5.87) then { execVM "test.sqf"; }; if (daytime > 6 && daytime < 6.05) then { execVM "test.sqf"; }; if (daytime > 7.83 && daytime < 7.88) then { execVM "test.sqf"; }; if (daytime > 8 && daytime < 5.89) then { execVM "test.sqf"; }; if (daytime > 11.85 && daytime < 11.90) then { execVM "test.sqf"; }; if (daytime > 12 && daytime < 12.05) then { execVM "test.sqf"; }; if (daytime > 16.83 && daytime < 16.88) then { execVM "test.sqf"; }; if (daytime > 17 && daytime < 17.05) then { execVM "test.sqf"; }; if (daytime > 20.4 && daytime < 20.45) then { execVM "test.sqf"; }; if (daytime > 20.83 && daytime < 20.88) then { execVM "test.sqf"; }; if (daytime > 21 && daytime < 21.05) then { execVM "test.sqf"; }; sleep 1; }; Will have a think about how to do this better. The switch block would be useful but would still need to loop it. Share this post Link to post Share on other sites
soolie 189 Posted November 2, 2017 if (daytime > 21 && daytime < 21.05) then { execVM "test.sqf"; }; sleep 1; so if it goes of at 21.01 it will go off again a second later and on and on for the next five minutes. If the sound itself is more than a second long it will be played over the sound before it. Does it need to be played over and over or just once for each time block? 1 Share this post Link to post Share on other sites
HazJ 1288 Posted November 2, 2017 I assumed he wanted it to just play once for that time but, at the same hour on the days to follow as well. Share this post Link to post Share on other sites
soolie 189 Posted November 2, 2017 Maybe something like this then? Not sure but curious so posting it anyway. while {true} do { _rightTime = daytime in [5.83,6.01,7.84,11.86,12.01,16.84,17.01,20.41,20.84,21.01]; if (_rightTime) then { execVM "test.sqf"; }; sleep 60; }; Share this post Link to post Share on other sites
pierremgi 4737 Posted November 2, 2017 2 hours ago, soolie said: Maybe something like this then? Not sure but curious so posting it anyway. while {true} do { _rightTime = daytime in [5.83,6.01,7.84,11.86,12.01,16.84,17.01,20.41,20.84,21.01]; if (_rightTime) then { execVM "test.sqf"; }; sleep 60; }; hmm, that can't work because there is so few chance to met one of the true condition. Daytime value is more precise than it appears in the returned value. Just hint in debug console: daytime tofixed 15 . See the problem? Any time you want to compare such changing value, use inequality test < or >, but never equality (== or isEqualTo). 1 Share this post Link to post Share on other sites
mat10193 13 Posted November 3, 2017 sorry for the late reply, work has been super busy. First, thank you all for your replies. Yes, i only want the sound to play once. and yes, when i changed the time from a single value to a range, it seemed to work better. @HazJ I will try what you suggested and post my results and also try to clean up my code. I am still a little new to writing scripts in Arma, I have the general idea and can make some simple scripts, but still learning to make better ones, so anything i can do to improve is great. Share this post Link to post Share on other sites
HazJ 1288 Posted November 3, 2017 8 hours ago, pierremgi said: hmm, that can't work because there is so few chance to met one of the true condition. Daytime value is more precise than it appears in the returned value. Just hint in debug console: daytime tofixed 15 . See the problem? Any time you want to compare such changing value, use inequality test < or >, but never equality (== or isEqualTo). Something like: if ((daytime > _rightTime) && (daytime < (_rightTime + 10))) then { Still, I think there is a better way to do this without that massive while-loop with if statements in. As I said, switch would be better but still need to loop it somehow I think. Or call a function that does some check... Hm. Share this post Link to post Share on other sites
pierremgi 4737 Posted November 3, 2017 Sure! The problem is I'm not sure to understand the aim of the script. [] spawn { while {true} do { waitUntil {sleep 30; dayTime > 16.5}; // 16:30 _date = dateToNumber; < any code>; waitUntil {sleep 30; dateToNumber > _date + 0.0027}; // more than 23h later (but below 24h) } }; The code will run everyday at 16:30 (in game) 1 Share this post Link to post Share on other sites