• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Update Dynamic text based on the score in Animate Multiple choice quiz

Explorer ,
Jun 15, 2023 Jun 15, 2023

Copy link to clipboard

Copied

Hi, I'm an animate novice, playing around with a html5 Multiple Choice quiz. It all works well, but I'd like to change the message displayed on the final score page dependent on the value of the total score achieved - so if  the total score is 0/3 a message something like "oops- total fail" appears. If the total score is 1/3 then a different message is displayed, and different messages again for each of 2/3 & 3/3. I'm sure it's a really simple thing to do, but any help would be greatly appreciated 

I have a dynamic textbox called "scorecomment" ready for the message, with the following code for the scoring:

var totalscore=3;
var thecoun=0;

this.totalscore.text=totalscore;
function scoreIt(){
thecount=thecount=1;
}

 

Views

172

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 15, 2023 Jun 15, 2023

Copy link to clipboard

Copied

oops, I made a typo in the code and missed a "t" off ... it should be :

var thecount=0;

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 15, 2023 Jun 15, 2023

Copy link to clipboard

Copied

Hi.

 

You can use a switch statement or an if-else chain. Like this:

 

Switch statement:

var currentScore = 0; // set other values here

switch(currentScore)
{
	case 0:
		this.scorecomment.text = "You scored 0.";
		break;
	case 1:
		this.scorecomment.text = "You scored 1.";
		break;
	case 2:
		this.scorecomment.text = "You scored 2.";
		break;
	case 3:
		this.scorecomment.text = "You scored 3.";
		break;
}

 

Else-if chain:

var currentScore = 0; // set other values here

if (currentScore === 0)
{
	this.scorecomment.text = "You scored 0.";
}
else if (currentScore === 1)
{
	this.scorecomment.text = "You scored 1.";
}
else if (currentScore === 2)
{
	this.scorecomment.text = "You scored 2.";
}
else if (currentScore === 3)
{
	this.scorecomment.text = "You scored 3.";
}

 

I hope this helps.

 

Regards,

JC

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 15, 2023 Jun 15, 2023

Copy link to clipboard

Copied

Thank you JC for the response, it's very much appreciated

Just a quick question though.... what do I write to set the other values? At the moment I only get "you scored 0" regardless of the score. 

As I say, I'm very much the novice in these things! 🙂

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 15, 2023 Jun 15, 2023

Copy link to clipboard

Copied

replace the quotes ("you scored x") with the text you want displayed

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 15, 2023 Jun 15, 2023

Copy link to clipboard

Copied

Hi, Robb.

 

The variable you use to keep track of the score shouldn't be redeclared when it's the time to show the message.

 

In my example, I declared currentScore immediately before checking for the values, but in your case you shouldn't do it.

If that makes sense.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 19, 2023 Jun 19, 2023

Copy link to clipboard

Copied

Hi JC,

Sorry for thdelay in responding - and thanks again for all of your help.

I'm afraid I'm being really thick here because I can't get my head around what I need to put and I'm tying myself up in knots!!

I've just realised that the "scorecomment" text should change depenent on the value shown in another dynamic text field called "finalscore" - which itself is fed from another dynamic text field called "currentscore" (this.finalscore.text=thiscurrentscore.text;) which derives it's value from "thecount" (this.currentscore.text=thecount;) etc...

I hope that makes some sense!

Again, appreciative of any help that you can throw in my direction.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 19, 2023 Jun 19, 2023

Copy link to clipboard

Copied

this.finalscore.addEventListener(Event.CHANGE,changeF);

 

function changeF(e:Event):void{

switch(this.finalscore.text)
{
case 0:
this.scorecomment.text = "You scored 0.";
break;
case 1:
this.scorecomment.text = "You scored 1.";
break;
case 2:
this.scorecomment.text = "You scored 2.";
break;
case 3:
this.scorecomment.text = "You scored 3.";
break;
}

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 20, 2023 Jun 20, 2023

Copy link to clipboard

Copied

Hi kglad, thank you for your help with this -  I've just tried adding your code but, when I test the movie it gets stuck at the spinning pre-loader and fails top open. I know I'm missing something really basic here! 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 20, 2023 Jun 20, 2023

Copy link to clipboard

Copied

my error.  i see this is an html5 project and i used as3 code.

 

what user action is triggering the various dynamic textfields to change values?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 21, 2023 Jun 21, 2023

Copy link to clipboard

Copied

Hi kglad,

no worries - it's a simple multiple choice quiz.

 

and exapmple question is:

var totalscore=3;
var thecount=0;

this.correctanswer1.ans1.text="Yellow";
this.wronganswer1.ans2.text="Pink";
this.wronganswer2.ans2.text="Blue";
this.wronganswer3.ans2.text="Purple";

this.totalscore.text=totalscore; 
function scoreIt(){
	thecount=thecount+1;
}


this.correctanswer1.addEventListener("click", fl_MouseClickHandler.bind(this));

function fl_MouseClickHandler()
{
	this.correctanswer1.play();
	this.wronganswer1.mouseEnabled=false;
	this.wronganswer2.mouseEnabled=false;
	this.wronganswer3.mouseEnabled=false;
	scoreIt();
	this.currentscore.text=thecount;
}


this.wronganswer1.addEventListener("click", fl_MouseClickHandler_2.bind(this));

function fl_MouseClickHandler_2()
{
	this.wronganswer2.mouseEnabled=false;
	this.wronganswer1.play();
	this.correctanswer1.mouseEnabled=false;
	this.wronganswer3.mouseEnabled=false;
	
}

etc.

and to get the finalscore it uses this:

this.finalscore.text=this.currentscore.text;

 

I need the final score to different different phrases in the "scorecomment" dynamic text box to read something like "bad luck, you failed this timefor a score of zero, right up to a score of 3 which would display something like "Well done, you maxed it!" etc.

 

I hope there's enough info there

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 21, 2023 Jun 21, 2023

Copy link to clipboard

Copied

The "scorecomment" is fed by the result in the dynamic text box "finalscore"

"totalscore" and "currentscore" are both dynamic text boxes

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 21, 2023 Jun 21, 2023

Copy link to clipboard

Copied

LATEST
function scoreIt(){
	thecount=thecount+1;
changeF(thecount);
}

function changeF(score){

switch(score)
{
case 0:
this.scorecomment.text = "You scored 0.";
break;
case 1:
this.scorecomment.text = "You scored 1.";
break;
case 2:
this.scorecomment.text = "You scored 2.";
break;
case 3:
this.scorecomment.text = "You scored 3.";
break;
}

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines