Jump to content
Sign in to follow this  
-JpS-RaptorMan

[Solved] Debugging with IF statement & isNil

Recommended Posts

Group,  

I'm looking to write the results of a function call to the log file.

I read up on IF's & isNil via the wiki.

Unsuccessfully... so I've started trying to tell what sort of data is coming back to me ...

Some of my tests ...

 

Trying to caputure the result of fn_getUIDPermissions in _c ... but really, this applies to every function I've tried to test yet 😞
 

("-----Test-----") call BIS_fnc_log;

_b = ('< my valid steam UID>' call fn_getUIDPermissions);

_c = if (_b) then [ {"true"}, {"false"}];

(format ["-----Test %1 ...", _c]) call BIS_fnc_log; 

Results in
 

"Test Dedicated server/BIS_fnc_log: ""-----Test-----"""
"Test Dedicated server/BIS_fnc_log: ""-----Test any ..."""

Another test just trying to tell if the stupid thing is nil or not ...

 

("-----Test-----") call BIS_fnc_log;

_b = ('< my valid steam UID>' call fn_getUIDPermissions);

_c = if (_b) then [ {"true"} else {"false"}];

(_c) call BIS_fnc_log; 

 

Which comes back 

 

"Test Dedicated server/BIS_fnc_log: ""-----Test-----"""


(originally I was doing the good stuff like calling it private etc - but don't know enough to know if that's the issue so I pulled that stuff out in favor of simplicity since no function has been captured in console)

Can someone shed some light on what's happening, maybe point me to something specific?

Thanks!

-R

Share this post


Link to post
Share on other sites

This:

 

_c = if (_b) then [ {"true"}, {"false"}];

 

should be:

 

_c = if (_b) then {"true"} else {"false"};

 

at least to my knowledge :eh:

Share this post


Link to post
Share on other sites

I've tried both ways & they are actually both documented on the link I posted for the IF statements ... any idea why I get "any" back when I format the true/false results?

Share this post


Link to post
Share on other sites

"true" and "false" are undefined variables hence "any" as a result.

true and false are booleans.

 

Edit: Unless _b is a boolean.

Edited by RCA3

Share this post


Link to post
Share on other sites
28 minutes ago, RCA3 said:

"true" and "false" are undefined variables hence "any" as a result.

true and false are booleans.

 

Edit: Unless _b is a boolean.


So, from a c/haskell/ruby/javascript/elixir background this makes no sense ... sqf is untyped basically?  Even if it was, I should get "true" or "false" back ... notice I'm putting string handlers around it - is this some weird BI thing where they perverted the typing 99% of the programmers in the world use?

Share this post


Link to post
Share on other sites
5 hours ago, -JpS-RaptorMan said:

Can someone shed some light on what's happening, maybe point me to something specific?

fn_getUIDPermissions returns array, you are treating it as boolean. Check your .rpt for errors

 

Share this post


Link to post
Share on other sites
8 hours ago, killzone_kid said:

fn_getUIDPermissions returns array, you are treating it as boolean. Check your .rpt for errors

 


That's actually why I'm here ... RPT doesn't ... even when I write the correct sequence & get a 1 back in the debug console status bar - my RPT will show the "Test" but not the other line.

I even built several versions of IF(<condition>) (isNil, check if value was above -1, etc) & was trying to have the if statement return strings. 

This got me thinking that I could skip that check & just act on the array itself, ty!

I'm getting the idea that ... the isNil check isn't handled by array object in the arma3 engine ... so I have to call isNil against the element of the array, not the array itself ...

 

// this
if(isNil _b[0])

// not this
if(isNil _b)

// though I suppose I could fake the 2nd one with ... results ...
_b = "";
count (_b);
hint str(_b);  // reports 0

_b = nil;
count (_b);
hint str(_b);  // dies silently


Thanks gang!!  This really helps

Also, the other reason nothing was showing up after the "TEST" in the RPT ... the mod wrapped that function I was calling in another ... I just noticed after debugging my if/isnil stuff and was going over the mod code ... right version was ... 

 

Quote

ASMS_fnc_getUIDPermissions

 

Share this post


Link to post
Share on other sites

You are using the isNil command wrong. You can use it to check the existence of variables by supplying the variable name, or the existing of the result of code by supplying a code block.

 

So using the former:

("-----Test-----") call BIS_fnc_log;

_b = '< my valid steam UID>' call fn_getUIDPermissions;
_c = if (isNil "_b") then {false} else {true}; // essentially the same as _c = !isNil "_b";

(format ["-----Test %1 ...", _c]) call BIS_fnc_log;

And using the latter:

("-----Test-----") call BIS_fnc_log;

_c = !isNil {'< my valid steam UID>' call fn_getUIDPermissions};

(format ["-----Test %1 ...", _c]) call BIS_fnc_log; 

 Format also takes care of converting boolean _c into a string, so no need to do the weird string "true"/"false" definition.

  • Like 1

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  

×