View Full Version : Interactive Quiz
Funky Monk
03-08-2006, 08:48 AM
I am really under pressure to complete a project and one piece is still outstanding. I need to create a quiz. The program logic is this:
# There are 10 questions
# Each question has a score out of 10
# The application needs to count this score and add it up at the end of the 10 questions
# The final score is displayed as a total out of 100
# The final score will be displayed with a comment based upon the score range - eg. under 20 "Man, that was crap".
Please help.
FrodoBaggins
03-08-2006, 09:38 AM
What is it you want to know?
Funky Monk
03-08-2006, 10:04 AM
I simply want to know how to put this together so that at the end of the quiz a score is displayed that shows the total out of 100. Each answer has a score out of 10 - 10 for the best answer, 5 for the next closest, 3 for the next, 1 for totally wrong. 10 questions - if the person choses the answer that corresponds to the score 5 their total is 50. Just don't know how to do this.
FrodoBaggins
03-08-2006, 12:34 PM
Use a variable that keeps track of the player's total score and add the score for each question answered to it. In the end display the total score.
Funky Monk
03-08-2006, 01:28 PM
That's what I am trying to do but I just can't get it to work.
FrodoBaggins
03-08-2006, 02:08 PM
Ok, now what have you got so far and what exactly doesn't work?
Funky Monk
03-08-2006, 02:17 PM
Well I am trying to modify a script that I found on the Internet. I contacted the author to ask him for help but there was no reply. Is there any chance you could just give me a bit of script to get started? I know I would rather learn this myself but I am facing a tight deadline and this is taking up all my time at the moment. Anything would help. Cheers.
FrodoBaggins
03-08-2006, 03:11 PM
ok, just a lil bit :P
Place all code in a seperate layer with nothing but code on it, no movieclips, buttons or whatever...
On the first frame you create the following:
_global.totalScore = 0;
For each button you specify something like this:
// Where button01 is a button on your stage.
_root.button01.onRelease = function(){
// the number depends on the score you get for the answer.
_global.totalScore += 3;
}
Does this help you enough?
monkeys_suck
03-08-2006, 03:24 PM
Why don't you create a textField object and use that to display your score? For example:
// Variables
var score_n = new Number(); // Score (number)
var score_max_str = new String("100"); // Max score
var score_str = new String(); // Score (string)
var question_value_n = new Number(10); // Point value for each question
// Create the text field
_root.createTextField("score_tfield", _root.getNextHighestDepth(), 0, 0, 200, 200);
// Check the answer and update the score properly
// answer_button is the button on stage that you use to answer
_root.answer_button.onRelease() = function {
if (/* Code to check answer goes here; Assume that this checks if the answer is correct */)
{
score_n += question_value_n; // Update the score based on how many points each question is worth
// This creates the string to show your score. It will look like this. Assume the user got 20 points out of 100.
// 20/100
score_str = score_n.toString() + "/" + score_max_str;
}
}
If someone else wrote this code, either they wrote it really sloppy or they didn't provide enough comments. If you can, post the .fla so we can take a look at it and be able to give you more detailed advice. Hope this helps.
Oops, sorry for not understanding your origional response. I'll try to post some code when I get home, if someone doesn't beat me to the punch.
Funky Monk
03-08-2006, 03:31 PM
Why don't you create a textField object and use that to display your score? For example:
// Variables
var score_n = new Number(); // Score (number)
var score_max_str = new String("100"); // Max score
var score_str = new String(); // Score (string)
var question_value_n = new Number(10); // Point value for each question
// Create the text field
_root.createTextField("score_tfield", _root.getNextHighestDepth(), 0, 0, 200, 200);
// Check the answer and update the score properly
// answer_button is the button on stage that you use to answer
_root.answer_button.onRelease() = function {
if (/* Code to check answer goes here; Assume that this checks if the answer is correct */)
{
score_n += question_value_n; // Update the score based on how many points each question is worth
// This creates the string to show your score. It will look like this. Assume the user got 20 points out of 100.
// 20/100
score_str = score_n.toString() + "/" + score_max_str;
}
}
If someone else wrote this code, either they wrote it really sloppy or they didn't provide enough comments. If you can, post the .fla so we can take a look at it and be able to give you more detailed advice. Hope this helps.
I assume that this is to display it on the same page. I need it to display 10 questions, then display results on the last page.
Funky Monk
03-08-2006, 03:42 PM
Hi frodo.
First up, I guess I should have mentioned that I am using Flash Professional version 8.
I tried running your code and got an error:
**Error** Scene=Scene 1, layer=elements, frame=19:Line 2: Statement must appear within on handler
_root.answer1.onRelease = function(){
This using the code:
_root.answer1.onRelease = function(){
// the number depends on the score you get for the answer.
_global.totalScore += 10; }
|
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.