Assigning strings to a global variable. -
Da_Noob - 21.02.2013
So I'm just testing some things what I can do with global variables and I'm stuck with something.
The problem is my code bugs after the global variable (string) is set to something.
This is my code.
pawn Код:
new VMessages[][MAX_PLAYERS][5];
Under OnPlayerConnect I set them to "", but it doesn't execute. Everything after this won't be executed either. (Eg. I have VMessages & then SetPlayerColor, it just stops at VMessages and doesn't set the player's color)
pawn Код:
for(new i = 0; i < 6; i++)
{
VMessages[playerid][i] = "";
}
And I'm scripting a voicemail thingy atm so I tried todo this:
pawn Код:
WrittenMessages[pID]++;
if(WrittenMessages[pID] == 6) { WrittenMessages[pID] = 0; strmid(VMessages[pID][0], msg, 0, strlen(msg), 255); VCaller[pID][0] = playerid; }
else if(WrittenMessages[pID] == 1) { strmid(VMessages[pID][0], msg, 0, strlen(msg), 255); VCaller[pID][0] = playerid; }
else if(WrittenMessages[pID] == 2) { strmid(VMessages[pID][1], msg, 0, strlen(msg), 255); VCaller[pID][1] = playerid; }
else if(WrittenMessages[pID] == 3) { strmid(VMessages[pID][2], msg, 0, strlen(msg), 255); VCaller[pID][2] = playerid; }
else if(WrittenMessages[pID] == 4) { strmid(VMessages[pID][3], msg, 0, strlen(msg), 255); VCaller[pID][3] = playerid; }
else if(WrittenMessages[pID] == 5) { strmid(VMessages[pID][4], msg, 0, strlen(msg), 255); VCaller[pID][4] = playerid; }
but the problem is it bugs when there are 2 voicemail messages written. Any ideas on how to fix this? It has something todo with the VMessages I suppose (As it blocks all the other codes under OnPlayerText)
EDIT: ohye, it compiles with no errors.
Re: Assigning strings to a global variable. -
Babul - 21.02.2013
think about the order for
pawn Код:
new VMessages[][MAX_PLAYERS][5];
..- the actual layout allows an non-defined amount of messages, *500 players, each with a lenght of 5 cells.
in a multi-dimensional array, you have to use the last dimension as strinlenght: thats [128].
the playerid belongs as one of the first parameters. to make it simle, you best use the first dimenion, and the string amount as second:
pawn Код:
new VMessage[MAX_PLAYERS][5][128];
this little change in the array will cause a little change aswell:
pawn Код:
OnPlayerConnect (playerid){
{
for(new i = 0; i < 5; i++)
{
VMessages[playerid][i] = "";
}
}
return 1;
you see the 3 dimensions used in the loop? VMessages[playerid][i]=""; i dont. its the strinlenght automatically storing 128 cells.
i think you'll figure out the rest. btw: a message[][5][] doesnt exist: an array [5] cells wide, goes from [0] to [4]. dont access [5].
Re: Assigning strings to a global variable. -
Da_Noob - 21.02.2013
I see. I've changed it in my script and it compiled with no errors.
I'm too tired now so I'll test it tomorrow. And also, I didn't know you couldn't acces the [5], thanks for telling me

.
Thanks!