Jump to content
Sign in to follow this  
firefly2442

Nil Variables vs. Empty String

Recommended Posts

I have some code that is creating a string:

_query = format ["Whatever('%1', '%2', '%3', '%4', '%5', '%6', '%7', '%8')", _puid, _name, _a, _b, _c, _d, _e, _f];

The problem is, some of the variables are Nil and have an empty string "". When I print out the string it looks like this:

Whatever('blah', 'blah2', ', ', ', ', '... etc.)

What I really want it to look like is to actually use those empty strings when formatting it:

Whatever('blah', 'blah2', '', '', '', ''...etc.)

Is this possible? Thanks in advance.

Share this post


Link to post
Share on other sites

How did you initialize the empty variables?

_a = "";

or

_a = [];

//Edit

I ABSOLUTELY suck at reading properly..

Well maybe try the other method with [], I'm not sure.

Edited by tryteyker

Share this post


Link to post
Share on other sites

Try this, I can't test it atm.

_query = format ["Whatever('%1', '%2')",str _puid,str _name];

No idea if it works on nil variables.

Maybe

private ["_a","_b"];

{
  if (isNil "_x") then {_x = ""};
} forEach [_a,_b];

Share this post


Link to post
Share on other sites

I'm pretty sure I tried the isNil check and assignment to an empty string "" already. The trouble is, the emptry string still evaluates to Nil which is not really technically correct IMO. I'll try it again to double check. Any other thoughts?

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×