Random questions about things I like

First question in my trivia game. (click on the image to go to the game)

So, yeah….this assignment.  All-in-all, not my favorite. I had a lot of frustration with this one. Creating the layout and arrays was easy. Everything after that, was not.

The biggest problem I had was getting my program to check the answer of the questions and compare it to what I had designated as the correct answer in my array. For instance, for my first question the array was:


questionArray1 = [“Who directed the movie Blade Runner?”, “Steven Spielberg”, “Ridley Scott”, “George Lucas”, ‘Christopher Nolan”, “2”];

So I wanted to be able to have the program check which button I had clicked and compare it to the last item in the array which was the number of the right answer. What I ended up doing, with much guidance from Evan, to whom I am very grateful, is to create a “questionCounter” variable(which was a uint) and have it go up every time I clicked the “Next” button. The question counter started at 1 so the program started at question 1 and each of the output boxes used the code Dr. Delwiche sent us in the e-mail to look at what the question counter was at and put the correct data into the corresponding box. The code looked something like this.

questionBox.text = this[“questionArray” + questionCounter[0];

and when the “Next” button was pushed, if you will remember, the program added 1 to the question counter and all the data in the boxes changed but still worked as each button was ascribed a string variable that was a number and that number was compared with the last item in each array. Here is what my code for this looked like (I have taken out one of the functions I used here for simplicities sake in making my point):

function onButtonOneClick(“1”):void


“checkAnswer” was another function I created to compare the data from button one being clicked, i.e. “1”, and compare it to the last item in the corresponding array. All of the other buttons did this too. What this allowed me to do was have a potentially infinite number of questions as each time an answer button was clicked it would compare that answer to the correct answer in the individual array for that question. This “checkAnswer” function would also move up one of the two counters I created to count right and wrong answers and update your score at the bottom. And then as I said, after you click the “Next” button it moved up the “questionCounter” and thus everything in the boxes. Once an arbitrary threshold is reached, basically one number more than the number of questions that exists, the program gives you your score, unless you got all of them right or wrong, in which case you get a special message praising or ridiculing you. If anyone wants to take a look at my code, it is posted up on the class website as andrewCoeTriviaGame.as.

The last few things I did in my program was to disable buttons and stuff so your score couldn’t keep going up even if you clicked on the screen. I also disabled the buttons after you answered a question and then reset back to being enabled and visible after you clicked the next button. This part wasn’t really hard or necessary, it was more an aesthetic and nitpicky thing that I wanted to do. The whole thing took me around 5 hours to do. It would have taken shorter but the first 2.5 hours were spent in frustration cussing at the computer and ultimately ended with me having nothing but the questions written and the stage set up.


About andrewtcoe

College student at Trinity University in San Antonio, TX majoring in Communications.
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s