[Problem] Variable doesn't gets assigned
#1

I've got a problem; I have 3 variables called age, origin, and sex.
I want to store information in them but somehow the information doesn't get stored in origin and age.

This is the code, I have no clue why it doesn't work.

Код:
playerAns(playerid, text[]) {
	new //Variabelen, hierin worden antwoorden gestored
		age,
		origin[128],
	  sex[128]
	;
	//Kijken in welke vraag hij zit
	switch(questions[playerid]) {
	  case 0: {
	    //Speler zit niet in vraag, melden dat hij niet kan chatten
	    SendClientMessage(playerid, 0xAFAFAFAA, "You are unnable to chat while you are in the tutorial");
	  } case 1: {
	    //Speler zit in een vraag, kijken of het een getal is
	    if(IsNumeric(text)) {
	      //Het is een getal, kijken of het een realistisch getal is
	      if(strval(text) < 100 && strval(text) >= 18) {
					//Correct formaat, opslaan
					RequestAns(playerid, 2);
					age = strval(text);
	      } else {
	        //Geen realistische leeftijd
	        SendClientMessage(playerid, 0xAFAFAFAA, "You have to fill in a realistic age");
	      }
	    } else {
	      //Geen nummer ingevoerd
	      SendClientMessage(playerid, 0xAFAFAFAA, "Fill in a number please");
	    }
	  } case 2: {
	    //Speler is in vraag 2
			format(origin, 128, "%s", text);
			RequestAns(playerid, 3);
	  } case 3: {
	    //Speler is in vraag 3, kijken wat hij invulde
	    if(!strcmp(text, "male", true)) {
	      //Speler beweerd mannelijk te zijn, gegevens opslaan
	      format(sex, 128, "male");
				SaveQuestions(playerid, age, origin, sex);
	    } else if(!strcmp(text, "female", true)) {
	      //Speelster beweerd vrouwelijk te zijn, gegevens opslaan
	      format(sex, 128, "female");
				SaveQuestions(playerid, age, origin, sex);
	    } else {
	      //Foutieve invoer
				SendClientMessage(playerid, 0xAFAFAFAA, "Incorrect input, fill in male of female");
	    }
	  }
	}
}
Reply
#2

It's because you use SaveQuestions() just on the case 3 (sex case).
Reply
#3

It saves all in case 3 because case 3 contains the last question
Reply
#4

Quote:
Originally Posted by Gvdsloot
It saves all in case 3 because case 3 contains the last question
Don't, it don't saves all in case 3 because the variables age and origin[128] are local variables, you need use it as global variables, and, to be more safe, one by player, like age[MAX_PLAYERS] and origin[MAX_PLAYERS][128].
Reply
#5

But the local variables are getting stored in files with dini, so a global variable isn't required
Reply
#6

Quote:
Originally Posted by Gvdsloot
But the local variables are getting stored in files with dini, so a global variable isn't required
Every time you use playerAns() all three variables are recreated.
Reply
#7

Oh, now I get it.
Thank you so much, I totally forgot it because the function becamed so long.
I feel so stupid
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)