fabrizio_t 58 Posted January 8, 2007 I need to check if a certain variable is undefined (and assign to it a default value in that case). Please give my your advice. Share this post Link to post Share on other sites
sbsmac 0 Posted January 8, 2007 I think isNil may be what you want. Despite the text on Biki I think it tests for definedness rather than a null value (which is what isNull is for). I'll do some checking when I can on my ArmA box... Share this post Link to post Share on other sites
Scillion 0 Posted January 8, 2007 Things you can put in Init.sqs score = "23" (this is a string global variable) spore=12 (this is a numeric global variable) "2" ObjStatus "HIDDEN" "markername" SetMarkerType "Empty" 1 SetRadioMsg "NULL" obj1=false obj2=false Hope this helps. If not good luck. Share this post Link to post Share on other sites
whisper 0 Posted January 8, 2007 I didn't know about isNil In OFP, it worked this way : A non defined variable points to objNull Therefore, you can use isNull. Do not use x==objNull, as explained ine the Biki. What's the difference between isNull and isNil, if any? Share this post Link to post Share on other sites
tj72 0 Posted January 8, 2007 Can you check if 0? If so then its undefined variable = 0 in init. Then when variable becomes defined its value is anything other than zero. I guess it depends on the type of variable but you should be able to reserve a specific value as undefined at init, once its defined as something then switch the value and check for it at the start of a function. I know this creates a definition but its reserved as only one thing but maybe for some reason the avariable has to be completely empty. Share this post Link to post Share on other sites
sbsmac 0 Posted January 8, 2007 Quote[/b] ]What's the difference between isNull and isNil, if any? I just confirmed it. Running this command player sidechat format ["defined: %1 null: %2",not isNil ("_v"),isNull _v] ; For _v =nil , results are "defined: FALSE null: BOOL" For _v =grpNull , results are "defined: TRUE null: TRUE" For _v =player , results are "defined: TRUE null: FALSE" Share this post Link to post Share on other sites
fabrizio_t 58 Posted January 9, 2007 "isNil" works like a charm. Thanks. Share this post Link to post Share on other sites
5133p39 16 Posted January 9, 2007 What's the difference between isNull and isNil, if any? The difference is that isNil can tell you whether the variable has been even initialized - eg. whether it exists, while isNull cannot determine whether the variable exists and is null, or it doesn't exists at all. Consider this:<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">myVar1 = ObjNull ? isNil myVar1 : Hint "Variable 1 does not exists" ? isNull myVar1 : Hint "Variable 1 is null" ? isNil myVar2 : Hint "Variable 2 does not exists" ? isNull myVar2 : Hint "Variable 2 is null" if you run the example above, you should get messages "Variable 1 is null", "Variable 2 does not exists", and "Variable 2 is null". Because the variable myVar1 is initialized (it exists, and it has been assigned a value of ObjNull), the first condition will return false while the second will return true. But both third and fourth conditions will return true because the variable myVar2 has not been initialized and doesn't exists. I hope i didn't obscured things more, by this "explanation", than cleared them Share this post Link to post Share on other sites