RonnieJ 10 Posted January 10, 2010 Hey guys... im having problems with the following: if(daytime > 19 or dayTime < 6) then { player sideChat "day"; _randN = floor(random 2); player sideChat format["ran %1",_randN]; _fireMission = switch (_randN) do { case 0: { ["IMMEDIATE","WP",0,5] }; case 1: { ["IMMEDIATE","HE",0,5] }; case 2: { ["IMMEDIATE","ILLUM",0,5] }; }; } else { player sideChat "night"; _randN = floor(random 1); _fireMission = switch (_randN) do { case 0: { ["IMMEDIATE","WP",0,5] }; case 1: { ["IMMEDIATE","HE",0,5] }; }; }; Apparently it dosent set _fireMission ... and even though its daytime I always end up in the else... any ideas how to solve the 2 issues? Share this post Link to post Share on other sites
Murklor 10 Posted January 10, 2010 Uhm yeah, it should end up in the else during the daytime. You're checking whether the time is over 19:00 (ie night) or before 06:00 (ie night once again) ;) Try if (dayTime >= 6 AND dayTime < 19) Also you can shorten it considerably by making an array and then randomizing the select: _fireMissions = [["IMMEDIATE","WP",0,5],["IMMEDIATE","HE",0,5],["IMMEDIATE","ILLUM",0,5]]; // Only need to be declared once _randFireMission = _fireMissions select (floor(random 2)); Share this post Link to post Share on other sites
Bon 12 Posted January 10, 2010 (edited) 2 things: You won't keep the local variable _fireMission when declaring it inside the if scope. Use private ["_fireMission"]; or declare _fireMission before entering the if-control statement. Otherwise the further script doesn't know this variable anymore. The probability for 2 when using floor(random 2) is damn low, because even if "random 2" returns 1.999999 the floor function makes 1 of it. Use round (random 2) instead. Edited January 10, 2010 by Bon Share this post Link to post Share on other sites
RonnieJ 10 Posted January 10, 2010 Great guys... but not working quite yet... tried this: _fireMissions = [["IMMEDIATE","WP",0,5],["IMMEDIATE","HE",0,5],["IMMEDIATE","ILLUM",0,5]]; if (dayTime >= 6 AND dayTime < 19) then { player sideChat "day"; _randFireMission = _fireMissions select (round(random 1)); } else { player sideChat "night"; _randFireMission = _fireMissions select (round(random 2)); }; player sideChat format["fire %1",_randFireMission]; I get "ANY" returned... so it doesent get set yet? Share this post Link to post Share on other sites
shuko 59 Posted January 10, 2010 2 things: The probability for 2 when using floor(random 2) is damn low, because even if "random 2" returns 1.999999 the floor function makes 1 of it. Use round (random 2) instead. floor (random 3) will give even chance for 2 as it covers values from 2 to 2.99. With round it would only use half (1.5 to 1.99). Share this post Link to post Share on other sites
Bon 12 Posted January 10, 2010 Great guys... but not working quite yet... tried this:_fireMissions = [["IMMEDIATE","WP",0,5],["IMMEDIATE","HE",0,5],["IMMEDIATE","ILLUM",0,5]]; if (dayTime >= 6 AND dayTime < 19) then { player sideChat "day"; _randFireMission = _fireMissions select (round(random 1)); } else { player sideChat "night"; _randFireMission = _fireMissions select (round(random 2)); }; player sideChat format["fire %1",_randFireMission]; I get "ANY" returned... so it doesent get set yet? Here u are doing the same as before. _randFireMission is a variable only local to the scope of the if-statement. It gets thrown away after exiting the if-statement. That's why it returns ANY. One possibility, as said, is, to reserve the variable name before entering the if-statement, as you did it now with _fireMissions. Another way would be to use "private". Share this post Link to post Share on other sites
RonnieJ 10 Posted January 10, 2010 Bon> Sorry m8! totally missed that one... didnt know varibels was contained in a if statement... I thought _var was varibels used in the sqf file and var was used across sqf files... But everything is working great now! So many thx to you all :) Share this post Link to post Share on other sites
dan3ko 10 Posted February 21, 2015 Hello guys. I have similar problems with "If" command. I want to add to my soldiers NV goggles only at certain hours of day and the rest of the day take off it. The code add correctly the goggles to the soldiers, but nothing more. Sorry for my english, if you don't understand something I wrote, please tell me. private "_guard"; _guard = [sold1,sold2,sold3,sold4,sold5,sold6]; if (!(daytime > 19 && daytime < 5)) then { { _x addItem "NVGoggles_INDEP"; _x assignItem "NVGoggles_INDEP"; } forEach _guard; }else{ { _x unassignItem "NVGoggles_INDEP"; _x removeItem "NVGoggles_INDEP"; }forEach _guard; }; Share this post Link to post Share on other sites
Norbak 10 Posted February 21, 2015 (edited) Why don't you make a trigger in Editor and: Condition : (local player) && {alive player} && (daytime > 19 AND daytime < 5) OR (local player) && {(vehicle player) in [sold1,sold2,sold3,sold4,sold5,sold6]} && {alive player} && (daytime > 19 OR daytime < 5) On ACT: Player addWeapon "NVGoggles" On DEACT: player removeWeapon "NVGoggles" I don't know if it 'll work. Or try to change AddItem and RemoveItem for AddWeapon and RemoveWeapon Edited February 21, 2015 by kyopower Share this post Link to post Share on other sites
dan3ko 10 Posted February 21, 2015 Thanks for your reply. I don't want to radd/remove goggles from player character. I want to do in IA characters. Addweapon and Remove weapon doesn't work. Share this post Link to post Share on other sites
Norbak 10 Posted February 21, 2015 AI doesn't need any googles. Is you mission a singleplayer? Share this post Link to post Share on other sites
dan3ko 10 Posted February 21, 2015 (edited) Yes, is single player for now. I know the IA doesen't need NV goggles, but for realism reasons I don't want the IA walk around Altis with goggles puting on in day time. Edited February 21, 2015 by dan3ko Share this post Link to post Share on other sites