Jump to content
Sign in to follow this  
spitfire007

Simple problem with testing if a string is null - can't figure it out.

Recommended Posts

I have tried to test a string to see if it is null using the methods below.

if format [_vehicleName] != "" then {

if (!isNull _vehicleName) then {

Neither will evaluate to true and let me enter the code after then.

All I am trying to do is make sure the variable _vehicleName actually has a value and is not "Any" or blank.

Thanks for the help.

---------- Post added at 10:48 ---------- Previous post was at 09:41 ----------

I am missing some coding fundamentals here ...

I tried to just keep it simple and evaluate if a string was true.

diag_log format ["TResult 2"];
diag_log format [CreatesSupplydrop2Success];

if CreatesSupplydrop2Success == "true" then {
diag_log format ["TResult 3 - passed true"];
};

If I look in the log I can see that TResult2 = "true" but I never get to TResult3.

Sorry for such a noob question but I am baffled.

Share this post


Link to post
Share on other sites

change this:

 if CreatesSupplydrop2Success == "true" then {

into this:

if (CreatesSupplydrop2Success) then {

Should work :)

Share this post


Link to post
Share on other sites

No .. that did not work for me :(

I am really at a loss here !

Here is the code in full.

if (CreatesSupplydrop2Success) then {
diag_log format ["TResult 3 - passed true"];
};

---------- Post added at 08:37 ---------- Previous post was at 08:27 ----------

No.. my mistake .. it worked !

Wow ....

So why does it not work when you use a string instead of making it boolean ?

And why do I need to put the brackets around CreatesSupplydrop2Success

Share this post


Link to post
Share on other sites

isnull checks if an object exists. To test if a string is defined you should use isnil.

if (!isNil "_vehicleName") then...

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  

×