I thought it was about time to publish a new post. This time I'm going to explain my solution to a problem I experienced during the build of the game: the teachers.
I thought of a way to make them random, but without a change of character. Every boss looks the same, but it's almost always a different teacher. It's actually a simple piece off code. I used an array to handle the different teachers and their questions and a second array with the answers.
By using a random number I was able to select a random question and look if the answer was correct. An example:
var vragen:Array = new Array( "vraag 1", "vraag 2" );
var antwoorden:Array = new Array(
"antwoord 1",
"antwoord 2"
);
var randomCijfer:int = Math.floor(Math.random()*vragen.length); vraag_txt.text = vragen[randomCijfer];