SA-MP Forums Archive
[Problem] Variable doesn't gets assigned - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: [Problem] Variable doesn't gets assigned (/showthread.php?tid=117771)



[Problem] Variable doesn't gets assigned - Gvdsloot - 01.01.2010

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");
	    }
	  }
	}
}



Re: [Problem] Variable doesn't gets assigned - MerLow - 01.01.2010

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


Re: [Problem] Variable doesn't gets assigned - Gvdsloot - 01.01.2010

It saves all in case 3 because case 3 contains the last question


Re: [Problem] Variable doesn't gets assigned - MerLow - 01.01.2010

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].


Re: [Problem] Variable doesn't gets assigned - Gvdsloot - 01.01.2010

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


Re: [Problem] Variable doesn't gets assigned - MerLow - 01.01.2010

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.


Re: [Problem] Variable doesn't gets assigned - Gvdsloot - 01.01.2010

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