Jump to content
bumyplum

getVariable returning <null>

Recommended Posts

I'm attempting to create a custom leader board with points i assign to players, how ever it just returns <null>.
 

private _arr = [];
    _pScore = {
        _playerPoints = _x getVariable "Players_Points";
        _playerName = name _x;
        _points = format["%1 - %2", _playerPoints, _playerName];
        _arr pushBack _points;
    }forEach playableUnits;

 

    {
        _Leaderboard_GUI_LB lbAdd _x;
    } forEach _arr;

 

how ever it adds them to the listbox and their names work fine just it doesn't seem to get the variable "Players_Points" and returns null.


_getStats = player getVariable "Players_Points";
 _updateStats = _getStats + 10;
player setVariable["Players_Points", _updateStats];

(locally this is how the points are applied to a player)

Share this post


Link to post
Share on other sites
3 hours ago, bumyplum said:

I'm attempting to create a custom leader board with points i assign to players, how ever it just returns <null>.
 

private _arr = [];
    _pScore = {
        _playerPoints = _x getVariable "Players_Points";
        _playerName = name _x;
        _points = format["%1 - %2", _playerPoints, _playerName];
        _arr pushBack _points;
    }forEach playableUnits;

 

    {
        _Leaderboard_GUI_LB lbAdd _x;
    } forEach _arr;

 

how ever it adds them to the listbox and their names work fine just it doesn't seem to get the variable "Players_Points" and returns null.


_getStats = player getVariable "Players_Points";
 _updateStats = _getStats + 10;
player setVariable["Players_Points", _updateStats];

(locally this is how the points are applied to a player)

That's because your "Players_Points" is undefined, most likely, try this:

_playerPoints = _x getVariable ["Players_Points",0];

Will return 0 if the player doesn't have the variable set, otherwise it will return the proper points.

 

Cheers

Share this post


Link to post
Share on other sites
18 minutes ago, Grumpy Old Man said:

That's because your "Players_Points" is undefined, most likely, try this:


_playerPoints = _x getVariable ["Players_Points",0];

Will return 0 if the player doesn't have the variable set, otherwise it will return the proper points.

 

Cheers

I've attempted this and even if they do have points then it just adds 0 for them

Share this post


Link to post
Share on other sites

Is the machine on which you're doing the servariable the same as the one you're doing the getvariable on?  If not add "true" as a 3rd param to setVariable to make it global. 

Share this post


Link to post
Share on other sites
3 hours ago, stanhope said:

Is the machine on which you're doing the servariable the same as the one you're doing the getvariable on?  If not add "true" as a 3rd param to setVariable to make it global. 

Alternatively one could handle stuff like this entirely on server and only broadcast points when needed.

 

Cheers

Share this post


Link to post
Share on other sites
6 hours ago, stanhope said:

Is the machine on which you're doing the servariable the same as the one you're doing the getvariable on?  If not add "true" as a 3rd param to setVariable to make it global. 

The player gets points by capturing a flag and ever x amount of time the player gets x amount of points,
i've changed how the points are added to the player to  //  player setVariable["Players_Points",  0, "true"];

which is executed locally on them self, how ever when trying to make a scoreboard it just adds my points as 0 as well as other players 



I've also attempted 

_namePlayer = format["%1_points", name player];
missionNamespace setVariable [_namePlayer , 100, "true"];

// for giving points


 

    private _arr = [];
    _pScore = {

        _namePlayer = format["%1_points", name _x];
        _getVarPoints = missionNamespace getVariable [_namePlayer, 0];
        _playerName = name _x;
        _points = format["%1 - %2", _getVarPoints, _playerName];
        _arr pushBack _points;

    }forEach playableUnits;


    {
        _Leaderboard_GUI_LB lbAdd _x;
    } forEach _arr;


// for adding to the list box

how ever it shows my points correctly just doesn't display other players it just displays 0 even if they have points

 

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

×