Weird output.
#1

Hi.
So, I've this code:
pawn Код:
g_Stats[gameid][gDuring] = true;
    nb_player[3] = g_Stats[gameid][gOwner] = playerid;
    //g_Stats[gameid][gMember] = nb_player;
    for(new i; i < MAX_PLAYER_PER_GAME; i++)
    {
        SCMF(playerid, RED, "%i & %i (i: %i)", g_Stats[gameid][gMember][i], nb_player[i], i);
        g_Stats[gameid][gMember][i] = nb_player[i];
        SCMF(playerid, RED, "%i & %i \n", g_Stats[gameid][gMember][i], nb_player[i]);
    }
    g_Stats[gameid][gGame] = gameid;
    p_Stats[playerid][pAccepted] = true;

    SCMF(playerid, -1, "%i & %i & %i & %i", nb_player[0], nb_player[1], nb_player[2], nb_player[3]);
    SCMTAE(RED,"» %i & %i & %i & %i", g_Stats[gameid][gMember][0], g_Stats[gameid][gMember][1], g_Stats[gameid][gMember][2], g_Stats[gameid][gMember][3]);
A lot of debug because this make no sence. There is the output:
Код:
[11:48:55] 1 & 1 (i: 0)
[11:48:55] 1 & 1  
[11:48:55] 0 & 2 (i: 1)
[11:48:55] 2 & 2  
[11:48:55] 4 & 3 (i: 2)
[11:48:55] 3 & 3  
[11:48:55] 0 & 4 (i: 3)
[11:48:55] 4 & 4  
[11:48:55] 1 & 2 & 3 & 4
[11:48:55] » 1 & 0 & 3 & 4
One value is changing by himself, plus some are aleady attributates to g_Stats[gameid][gMember] which is not possible. It's should be 0 everywhere.

Edit : SCMF = SendClientMessageFormatted & SCMTAE = SendClientMessageToAllEx
Reply
#2

Can you describe to us what are those variables for and tell us what you wanted to make? How do we know if you are just printing "1 & 1" if we just look at the variable name that could have a lot meanings. Except the "(i: 0)" that we know it's the player id.... And which value that change itself??
Reply
#3

I think he is referring to the change in values of the variables he printing they supposed to be same as he assigning it with themselves
The problem might be in SCMTAE function try printing last statement in SCMF (just a guess me even don't completely understood what you asking)
Reply
#4

I'll give you the full code:
PHP код:
CMD:startgame(playeridparams[])
{
    new 
nb_player[MAX_PLAYER_PER_GAME];
    if(
sscanf(params"A<i>(-1)[3]"nb_player))
        return 
SCM(playerid, -1"/startgame [player2] [player3] [player4]");
    new 
gameid GetFreeSlot();
    if(
gameid == INVALID_GAME_ID)
        return 
SCM(playeridRED"Bla bla bla");
    for(new 
iMAX_PLAYER_PER_GAMEi++)
    {
        if(!
IsPlayerConnected(nb_player[i]) && nb_player[i] != -1)
            return 
SCMF(playeridRED"Invalid.");
        if(
nb_player[i] == -1)
            continue;
        
SCMF(nb_player[i], RED"sm -");
        
p_Stats[nb_player[i]][pInvited] = false;
        
p_Stats[nb_player[i]][pGamemid] = gameid;
    }
    
g_Stats[gameid][gDuring] = true;
    
nb_player[3] = g_Stats[gameid][gOwner] = playerid;
    
//g_Stats[gameid][gMember] = nb_player;
    
for(new iMAX_PLAYER_PER_GAMEi++)
    {
        
//SCMF(playerid, RED, "%i & %i (i: %i)", g_Stats[gameid][gMember][i], nb_player[i], i);
        
printf("%i & %i (i: %i)"g_Stats[gameid][gMember][i], nb_player[i], i);
        
g_Stats[gameid][gMember][i] = nb_player[i];
        
//SCMF(playerid, RED, "%i & %i \n", g_Stats[gameid][gMember][i], nb_player[i]);
        
printf("%i & %i \n"g_Stats[gameid][gMember][i], nb_player[i]);
    }
    
g_Stats[gameid][gGame] = gameid;
    
p_Stats[playerid][pAccepted] = true;
    
// SCMF(playerid, -1, "%i & %i & %i & %i", nb_player[0], nb_player[1], nb_player[2], nb_player[3]);
    // SCMTAE(RED,    "» %i & %i & %i & %i", g_Stats[gameid][gMember][0], g_Stats[gameid][gMember][1], g_Stats[gameid][gMember][2], g_Stats[gameid][gMember][3]);
    
printf("» %i & %i & %i & %i"g_Stats[gameid][gMember][0], g_Stats[gameid][gMember][1], g_Stats[gameid][gMember][2], g_Stats[gameid][gMember][3]);
    
printf("%i & %i & %i & %i"nb_player[0], nb_player[1], nb_player[2], nb_player[3]);
    if(
AllPlayersAcceptedAGame(gameid))
    {
        
SCM(gameidRED"-");
        
g_Stats[gameid][gStarted] = true;
    }
    return 
1;

pawn Код:
enum g_enum
{
    bool:gDuring = false,
    bool:gStarted = false,
    gGame,
    gOwner,
    gMember[4] = 0,
//...
new g_Stats[MAX_GAME][g_enum]
g_Stats is game's stats. p_stats is player's stats.

output with print instead of functions:
Код:
[13:20:47] 1 & 1 (i: 0)
[13:20:47] 1 & 1 

[13:20:47] 0 & 2 (i: 1)
[13:20:47] 2 & 2 

[13:20:47] 4 & 3 (i: 2)
[13:20:47] 3 & 3 

[13:20:47] 0 & 4 (i: 3)
[13:20:47] 4 & 4 

[13:20:47] » 1 & 0 & 3 & 4
[13:20:47] 1 & 2 & 3 & 4
Edit: Don't look at SCMF without arguments, I've not finish yet.
Reply
#5

Quote:
Originally Posted by Dayrion
Посмотреть сообщение
pawn Код:
enum g_enum
{
    bool:gDuring = false,
    bool:gStarted = false,
    gGame,
    gOwner,
    gMember[4] = 0,
//...
new g_Stats[MAX_GAME][g_enum]
Hey hey, what are you doing with that enum... Why you set it = false and = 0... These are not for setting default values for those variable, it's to change the enumeratical order... If you do it like that:
Код:
bool:gDuring will be number 0
bool:gStarted will be number 0 so = bool:gDuring?
gGame will be number 1
gOwner will be number 2
gMember[0] will be number 0 so = bool:gDuring?
gMember[1] will be number 1 so = gGame?
gMember[2] will be number 2 so = gOwner?
gMember[3] will be number 3
Please do like this if you want a "default" value:
pawn Код:
enum g_enum
{
    bool:gDuring,
    bool:gStarted,
    gGame,
    gOwner,
    gMember[4],
// ...
new g_Stats[MAX_GAME][g_enum];
// well you are wanting it to be set "0" so i don't assign anymore, but if you want to make it "1", then do like this:
g_Stats[0][gDuring] = true;
Also make sure to reset them again after the game is done/before starting the game.
Reply
#6

Ohh.. Ye'p.. I'm pretty stupid.
I though enum increment if you have set value for the first variable. Anyway, thanks you. c:
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)