[Solved] Language Selection for Number Wizard

Hi guys,

So, I know I may be jumping ahead here, but I thought I would like to implement a language selection option right at the start of Number Wizard. I don’t have a lot of experience in programming, so I did the best I could:

As I hope you can see, it works quite well as long as the user don’t fiddle around too much. As most of the input reading is done by the Update() function, which is called every frame, anytime the user presses one of the buttons I assigned to each language, the program will re-start in that language. Plus, if they don’t choose a language at all and just press the up and down arrows, the program will run anyway.

Is there any way to lock down the buttons the user can press at any given time to only the ones I want them to be able to press? Or is there a better way to do this altogether?

Thanks and sorry for any mispellings, english is not my first language.

1 Like

Hello Murilo,

In my opinion the best way to do this is making another scene (which will run before the game scene), that gives the option to the player choose which language he rather play. You can save a int value or a string into a variable within a script that Dont destroy on load and that saves the option that the player choose and will carry it to the next scene (the Game Scene). Most of those features will be covered in the Block Breaker classes, but let me know if you need any help implementing it, you can send me private messages in Portuguese, I’m Brazilian too.

By the way, welcome to the community! :slight_smile:

2 Likes

I just realized that you are on the console version of Number Wizard, sorry!

In this case, in order to don’t work with multiple scripts and scenes, I think that the best way to do it would be to keep track if the player has already chosen the language that he wants within a bool and prevent the player from changing the language again, using if statements:

bool LanguageChosen = false;
int max;
int min;
int guess;
int lang = 0; 

	// Use this for initialization
	void Start () {
		StartGame();
	}

	void StartGame(){
		print ("Choose the languange:");
		print ("1 for English");
		print ("2 para Português (BR)");
	}

	void StartGameEn(){

		max = 1000;
		min = 1;
		guess = 500;

		print ("!==========================!");
		print ("Welcome to Number Wizard!");
		print ("Pick a number in your head, but don't tell me.");
		print ("The highest number you can pick is " + max);
		print ("The lowest number you can pick is " + min); 

		print ("Is the number higher or lower than " + guess + "?");		
		print ("Press up for higher, down for lower and enter for equal");

		max = max + 1;	
	}

	void StartGamePtBr(){

		max = 1000;
		min = 1;
		guess = 500;

		print ("!==========================!");
		print ("Bem Vindo(a) ao Number Wizard!");
		print ("Pense em um número, mas não me conte ainda!");
		print ("O maior número que você pode escolher é " + max);
		print ("O menor número que você pode escolher é " + min); 

		print ("O número que você pensou é maior ou menor que " + guess + "?");		
		print ("Pressione cima para maior, baixo para menor ou enter para igual");

		max = max + 1;	
	}

	void NextGuess(){
		guess = (max + min) /2;


		if (lang == 1){

			print ("Is the number higher or lower than " + guess + "?");
			print ("Press up for higher, down for lower and enter for equal");

		} else if (lang == 2){

			print ("O número é maior ou menor que " + guess + "?");
			print ("Pressione cima para maior, baixo para menor ou enter para igual");

		}
	}
	void Update()
	{
		if (LanguageChosen == false){
			if (Input.GetKeyDown(KeyCode.Alpha1)){
				StartGameEn();
				lang = 1;
				LanguageChosen = true;

			} else if (Input.GetKeyDown(KeyCode.Alpha2)){
				StartGamePtBr();
				lang = 2;
				LanguageChosen = true;
			}
		}


		else {
			if (Input.GetKeyDown (KeyCode.UpArrow)) {

				//Up key pressed
				min = guess;
				NextGuess ();

			} else if (Input.GetKeyDown ("down")) {

				//Down key pressed
				max = guess;
				NextGuess ();

			} else if (Input.GetKeyDown ("return") && lang == 1) {
				print ("I won!");
				StartGameEn ();

			} else if (Input.GetKeyDown ("return") && lang == 2) {
				print ("Eu venci!");
				StartGamePtBr ();
			}
		}
	}

just tried it, seems to work as intended.
Let me know if I can be of further help.

2 Likes

Thanks, João!

The bool variable solution seems like an elegant one! I’ll try it out later and let you know!

Great to see the community is so active and prompt to respond!

2 Likes

You are welcome @alomurilo,

This is a very good community, people around here are very helpful! Make sure to be an active user in the community too, it helps to make the experience through the course be as rich as possible.

I’ll be waiting to see if you managed to make it work as intended!

1 Like

Worked like a charm! Thanks again, João!

1 Like

Privacy & Terms