Jump to content
🛡️FORUMS ARE IN READ-ONLY MODE Read more... ×
Sign in to follow this  
Chromium

isNil Woes

Recommended Posts

Well, after hammering away at script for a while, I've pinned down a problem I'm having with isNil.

The following code does not return, ever:

if (isNil _tmr) then {
_tmr = (-120);}

Take out the "if... {" and the "}" and _tmr gets a value set of -120. I have to assume I'm coding the if statement wrong, but I can't for the life of me see anything off. I've tried a few variations on the condition, but no use there. (isNil ("_tmr")) doesn't work either. The only method for testing this is a simple

hint format ["%1",_tmr]

but I don't think that it's the testing method that is flawed.

Any help?

Share this post


Link to post
Share on other sites

It's a Scope problem :)

private ["_tmr"];

if (isNil "_tmr") then { _tmr = -120 };

Share this post


Link to post
Share on other sites

Well, while that gets my tests to return (:o) I still have an issue: they return as "any", indicating the variable is still nil.

Full code of the SQF:

private ["_tmr"];
if (isNil _tmr) then
{
   _tmr = -120;
};
if ((time - _tmr) >= 120) then 
{
_tmr = time;
player setCaptive 1;
hint "Stealthed";
sleep 10;
player setCaptive 0;
hint "Exposed";
}
else 
{
hint format ["Cooldown not expired, %1 seconds left",(120-(time - _tmr))];
};

Thanks for your help so far!

Share this post


Link to post
Share on other sites

Thanks guys! Hard to believe I packed that many problems into like 10 lines. :P Sorry for wasting time, but thanks for all the help!

Share this post


Link to post
Share on other sites
Sign in to follow this  

×