WIP. Space Words (VII)

Submitted by tech4life on

We have also worked in the system to generate new words.

For this, we've created a couple of files in the assets folder. Each one with a huge amount of words, separated by comma. One in english and the other in spanish.

 

To select a new word, we only need to open the file, load the content in a variable, and convert it to an array, by telling to the split function that the ',' is the separation value.

These will generate an array with all the words.

 

 

Then we only need to generate a random number, and get the position in the array. To finish we remove that word from the array so it won't appear again.

The load of the file is made each time a new game is created, that means, at the beginning, and after the player death. So words will be again ready to appear in the game.

 

func generate_new_word(type):
	if type == 1:
		var file
		if (langSelected == "EN"):
			file = FileAccess.open("res://assets/all_words.txt", FileAccess.READ)
		elif (langSelected == "ES"):
			file = FileAccess.open("res://assets/all_words_es.txt", FileAccess.READ)
		else :
			file = FileAccess.open("res://assets/all_words.txt", FileAccess.READ)
		var file_opener = file.get_as_text()
		all_words_array=file_opener.split(",")
		all_words_array.remove_at(all_words_array.size()-1)
		
	var i = randi() % all_words_array.size()
	actualWord = all_words_array[i]
	all_words_array.remove_at(i)
	lengthWord = actualWord.length()

 

Tags