lundi 21 novembre 2016

score and number of questions answered //as3 game

i've been doin a school project (a game in as3), and there's a part of it which i got stuck. i'm using some dynamic text, but the values inside the vars i've created aren't showing there.

here is part of the code i'm using:

var scorePrincipal = 0;
var counter = 0;

if (counter < 5){
    RandomizeQ();
    counter++;
} else{
    gotoAndPlay(51);
}

in this scene ive got kind of a quiz, which adds points for the player if this chooses the right answer, otherwise this one loses the same amount he'd gain (2 points).

RandomizeQ() is a function for randomizing frames //it works like this: when player gets to this scene, a random question is selected for this one answering it, and there'll be 5 random questions for the player answering - if the answer is wrong, scorePrincipal is supposed to take 2 points from players score, otherwise, it is added 2 points for the players score.


This is the code i'm using for the questions:

q1_a.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndPlayFromFrame);

function fl_ClickToGoToAndPlayFromFrame(event:MouseEvent):void
{
    scorePrincipal = scorePrincipal + 2;
    trace(counter);
    trace(scorePrincipal);
    gotoAndPlay(52);

}


q1_b.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndPlayFromFrame_2);

function fl_ClickToGoToAndPlayFromFrame_2(event:MouseEvent):void
{
    if(scorePrincipal>1){
        scorePrincipal = scorePrincipal - 2;
    } else
    scorePrincipal = 0;
    gotoAndPlay(52);

}


q1_c.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndPlayFromFrame_3);

function fl_ClickToGoToAndPlayFromFrame_3(event:MouseEvent):void
{
    if(scorePrincipal>1){
        scorePrincipal = scorePrincipal - 2;
    } else
    scorePrincipal = 0;
    gotoAndPlay(52);

}

q1_d.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndPlayFromFrame_4);

function fl_ClickToGoToAndPlayFromFrame_4(event:MouseEvent):void
{
    if(scorePrincipal>1){
        scorePrincipal = scorePrincipal - 2;
    } else
    scorePrincipal = 0;
    gotoAndPlay(52);

}

52 is the frame which contains the randomizer code

this is how my stage is for this scene

Aucun commentaire:

Enregistrer un commentaire