CarlGustaffa 4 Posted October 12, 2007 Hi I'm trying to set weather based on previous weather and a random input. Yes, I've seen som weather scripts but I don't think they do what I need, or, want Also considering this a little experiment with the sqf syntax which I am learning. Note, all _variables initialized outside the loops. Say the overcast is 0. Now I need to use a for loop counting upwards using the for [{BEGIN}, {CONDITION}, {STEP}] do syntax. BEGIN is replaced with _i=_ovc_curr, as this is the initial point. CONDITION is replaced with _ovc_curr < _ovc_targ, since I want to continue as long as this is met. And finally, STEP is a simple _i = _i +1 statement. This seems to wok just fine. However, I also need to check against what the weather is when I start the loop, since the weather will improve instead of deterioate in certain conditions. Now I suddenly might have to count downwards. So now I need to have an if else thing going on, choosing which for loop I wish to execute. But I keep hitting the wall on this one. I also tried doing only one for loop but with nested conditionals inside -- again nothing but error codes. Nested: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> for [ {_i=_ovc_curr}, {if(_ovc_curr < _ovc_targ) then {_i < _ovc_targ}; else {_i > _ovc_targ};}, {if(_ovc_curr < _ovc targ) then {_i=_i+0.01}; else{_i=_i-0.01}; ] do   { ...the code...;   } Separate: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> if (overcast < _ovc_targ) then {   for [{_i=overcast}, {_i < _ovc_targ}, {_i=_i+0.01}] do   {   ...code...   }; }; else { hint "test"; }; The lower one apparently works until I add that else {...code...}; stuff. Where am I going wrong? Tried to follow the biki as close as possible, but I'm stuck Share this post Link to post Share on other sites
vova _fox 0 Posted October 12, 2007 wrong code: if () then {} ; else {}; right if () then {} else {}; Share this post Link to post Share on other sites
CarlGustaffa 4 Posted October 12, 2007 Thank you very much! Well, it doesn't work as I was hoping, but at least now I'm getting closer... Gawd I hate semicolons ;-) Share this post Link to post Share on other sites
sbsmac 0 Posted October 13, 2007 If you spawn the following code (sqf) it will slowly track your target weather. You can chance the STEP_TIME or STEP_SIZE defines to change the responsiveness. ovc_targ has been changed to a global variable to allow you to set the target weather from elsewhere in the mission. <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> #define STEP_TIME 0.1 #define STEP_SIZE 0.01 while {true} do { _diff = ovc_targ - overcast; if (abs _diff > STEP_SIZE) then { //Get the step - either -1 or +1 _stepDir = (abs _diff )/ _diff; STEP_TIME setOvercast (overcast + _stepDir*STEP_SIZE); }; sleep STEP_TIME; }; _ *edit* - oops, got the step the wrong way round Share this post Link to post Share on other sites
sickboy 13 Posted October 13, 2007 cool idea about the defines sbsmac :-) I should keep that one in mind Share this post Link to post Share on other sites
sbsmac 0 Posted October 13, 2007 Just bear in mind that #include only works for _sub_directories so if you want to stick definitions in a common header file you need to bury it at the bottom of the file heirarchy - a bit annoying Share this post Link to post Share on other sites