pureaudio
09-17-2008, 02:35 PM
Hi all..
I'm writing a simple quiz game and I'm trying to use a technique that will speed up the way a user can accumulate scores.. I intend to have a function that watches for user input and if answer = correct then change score. If answer = wrong pause for 1 second.. (giving time to change answer) then deliver negative score.
my code works for the most part (though only in partial functionality at this stage) BUT!!!! for some reason the very first question doesn't work, though all the following questions do. In my tests, for some reason the answer1.text.length is wrong and the simple answer check fails.. I can't understand it!!
Here's my code
var Score = 0;
var Answer:String;
var digitcounter:int;
var answercounter:int;
answer1.addEventListener(Event.CHANGE, changetext);
function changetext(e:Event):void
{
// This is part of a function that will later be improved to make the scoring system more intuitive //
digitcounter = String(Answer).length;
answercounter = answer1.text.length ;
if (answercounter == digitcounter)
{
checkanswer();
}
// For debugging//
trace(int(answer1.text));
}
function checkanswer():void
{
// Answer is generated in another function. There are no problems with that..//
if (answer1.text == Answer)
{
Score = Score +1;
}
else
{
Score = Score -1;
}
score.text = Score;
answer1.text = "";
stage.focus = answer1;
refreshno();
}
I'm writing a simple quiz game and I'm trying to use a technique that will speed up the way a user can accumulate scores.. I intend to have a function that watches for user input and if answer = correct then change score. If answer = wrong pause for 1 second.. (giving time to change answer) then deliver negative score.
my code works for the most part (though only in partial functionality at this stage) BUT!!!! for some reason the very first question doesn't work, though all the following questions do. In my tests, for some reason the answer1.text.length is wrong and the simple answer check fails.. I can't understand it!!
Here's my code
var Score = 0;
var Answer:String;
var digitcounter:int;
var answercounter:int;
answer1.addEventListener(Event.CHANGE, changetext);
function changetext(e:Event):void
{
// This is part of a function that will later be improved to make the scoring system more intuitive //
digitcounter = String(Answer).length;
answercounter = answer1.text.length ;
if (answercounter == digitcounter)
{
checkanswer();
}
// For debugging//
trace(int(answer1.text));
}
function checkanswer():void
{
// Answer is generated in another function. There are no problems with that..//
if (answer1.text == Answer)
{
Score = Score +1;
}
else
{
Score = Score -1;
}
score.text = Score;
answer1.text = "";
stage.focus = answer1;
refreshno();
}