문제

I'm doing a project which consists in creating a game of the goose-like (with a quiz aspect) and I've some troubles to identify a player when he comes in the game.

I want to do something like, a playerNumber which is increment when a player come.

I've tried something like this but the problem is that when a player comes the variable "joueur" return to 0.

var joueur = 0;
    if (typeof numJoueur == 'undefined')
    {
        numJoueur = joueur;
        joueur++;
        var str = "Je suis le joueur " + numJoueur;
    }

Do you have some solutions/propositions to overtake the problem ? :)

PS : Sorry for my English, I'm French (as shown in my code ^^)

도움이 되었습니까?

해결책

Is the joueur variable declared inside the scope of the route, like so:

function newplayerroute(req, res, next) {
    var joueur = 0;
    if (typeof numJoueur == 'undefined')
    /* ... */
}

If it is, then that variable gets reset every time this route/function is called. You'll need to declare it in a higher scope:

var joueur = 0;
function newplayerroute(req, res, next) {
    if (typeof numJoueur == 'undefined')
    /* ... */
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top