Jump to content
Danskkat

Scalar NaN - Need Other Set of Eyes

Recommended Posts

Getting a Scalar NaN and it's weirding me out because I believe I'm calling it the exact same way as a previous iteration in the same code and it worked fine there. Would love someone else to take a look at this with me.

(Inside a [] spawn, and everything else works fine. Adding what I believe is the only necessary bits of the code)
//Declaration of Variable before a While {true} loop
_gameStartTime = floor time;

//Declaration inside of the loop
_timerFix = floor time;
 

//Previous instance where this worked, ignore the "enemies in Sim stuff, just wanted to make sure copy & pasted as-is
_hintFormattedTimed = format ["Enemies in Sim %1 \nTime: %2", ({alive _x && side _x == independent} count allUnits), _timerFix - _gameStartTime];
[_hintFormattedTimed] remoteExec ["hintSilent", 0, false];

//Where it fails, and my attempt at fixing it by making a new variable to contain it
 _finalTime = _timerFix - _gameStartTime;
 _timeScore = format ["Time to Completion: %1", _finalTime];
[[_timeScore, "PLAIN"]] remoteExec ["titleText", 0];

When that is called in-game I get Time to Completion: Scalar NaN.
I get that whole "Not a Number" thing, but I can't figure out why the working remoteExec on a formatted version of _timerFix - gameStartTime would work just fine but the new remoteExec is unhappy.

Anyway, thank you for looking!

Share this post


Link to post
Share on other sites

So what you're saying is
 

_hintFormattedTimed = format ["Enemies in Sim %1 \nTime: %2", ({alive _x && side _x == independent} count allUnits), _timerFix - _gameStartTime];


works but
 

_finalTime = _timerFix - _gameStartTime;
 _timeScore = format ["Time to Completion: %1", _finalTime];


somehow doesn't? You must be doing something else you are not showing to cause the error.

Share this post


Link to post
Share on other sites

Same as in code, copy/pasted.
Here's the whole spawn, then.

[] spawn
    { 
    _gameStartTime = floor time;
    while {true} do
        {
        terroristsLeft = ({alive _x && side _x == independent} count AllUnits);
        _hintFormattedCasual = format ["Enemies In Sim: %1", ({alive _x && side _x == independent} count AllUnits)];
        if (GameTimer == 0) then
            {
            [_hintFormattedCasual] remoteExec ["hintSilent", 0, false];
            }
            else
            {
            _timerFix = floor time;
            _hintFormattedTimed = format ["Enemies in Sim %1 \nTime: %2", ({alive _x && side _x == independent} count allUnits), _timerFix - _gameStartTime];
            [_hintFormattedTimed] remoteExec ["hintSilent", 0, false];
            };
        sleep 1;
        HostagesAlive = ({alive _x && side _x == civilian} count allUnits);
        if (HostagesAlive < HostageCount) then
            {
            [["<t color='#ff0000' size='5'>A HOSTAGE WAS KILLED</t><br/>--------------------<br/><t color='#ff0000' size='5'>MISSION FAILURE</t>", "PLAIN", 0, true, true]] remoteExec ["titleText", 0];
            sleep 5;
            ["HostageFail", false, 5] call BIS_fnc_endMission;
            };
        if (terroristsLeft == 0) then
            {
            [["<t color='#0078FF' size = '5'>ALL HOSTILES ELIMINATED</t>", "PLAIN", 0, true, true]] remoteExec ["titleText", 0];
            sleep 5;
                if (GameTimer == 1) then
                    {
                    _finalTime = _timerFix - _gameStartTime;
                    _timeScore = format ["Time to Completion: %1", _finalTime];
                    [[_timeScore, "PLAIN"]] remoteExec ["titleText", 0];
                    sleep 5;
                };
            ["MissionSuccess", true, 5] call BIS_fnc_endMission;
            };
        };
    };
 

Share this post


Link to post
Share on other sites

You have 2 problems.
1  _hintFormattedCasual is not the same variable. I don't know how did you manage, but one of the names contains extra symbol:  _hintFo rmattedCasual <- between o and r
2.  _timerFix is defined inside one scope will be undefined inside a different scope unless the different scope is child to the original scope. So yeah _finalTime = _timerFix - _gameStartTime; <- undefined

  • Like 1

Share this post


Link to post
Share on other sites

I am very confused on that first one. Also extra confused because that one's never failed on me. Huh.

 

So, let me see if I can understand this... _timerFix is defined inside of a conditional that relies on GameTimer being 1... and is called again later in the loop where GameTimer also has to be 1... but because they're not defined in the same conditional they can't talk across to each other?

Would making them both public variables help?

 

(Apologies for dumb language, largely self-taught code means I am bad at communicating it sometimes.)

Share this post


Link to post
Share on other sites

I make this simple:

if (true) then {_var = 123; systemchat str [_var]};
if (true) then {systemchat str [_var]};


Result is 
[123]
[any]

Second scope with _var has no relation to the first one

  • Like 1

Share this post


Link to post
Share on other sites

Okay, I think that's what I was getting at, but that's definitely a good way of explaining it.
Thank you so much for the help! I was bashing my head against this for days!

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

×