PDA

View Full Version : Keeping score in 2-player trivia game


apprentice
09-12-2002, 02:18 AM
I'm trying to create a 2-player trivia game that utilizes a single scoring function. In order to do this for 2 people, I've tried to use a variable 'who', but am still not getting it right. For some reason the 'who' variable is never reassigned, thus giving all the points to player 1. Everything else works okay, except for this. Thanks in advance for any help!

The first script is placed in frame 1 of the main movie, and the second script is placed on an MC residing on frame 2 of the main movie.
---------------------------------------------------------------------------
who=1;
score1=0;
score2=0;
newscore1=score1;
newscore2=score2;


function right(){
if(who==1){
score1 += 10;
newscore1 = score1;
updateAfterEvent();
_root.homerun.gotoAndPlay(2);
}
else if(who==2){
score2 += 10;
newscore2 = score2;
updateAfterEvent();
_root.homerun.gotoAndPlay(2);
}
}

function wrong(){
if(who==1){
score1 -= 10;
newscore1 = score1;
updateAfterEvent();
_root.homerun.gotoAndPlay(2);
}
else if(who==2){
score2 -= 10;
newscore2 = score2;
updateAfterEvent();
_root.strike.gotoAndPlay(2);
}
}
------------------------------------------------------------------------------

onClipEvent(keyDown) {
if(Key.isDown(65)){
who=1;
_root.buzz.gotoAndStop(2);
_root.whobuzzed.gotoAndPlay("p1");
}
else if(Key.isDown(76)){
who=2;
_root.buzz.gotoAndStop(3);
_root.whobuzzed.gotoAndPlay("p2");
}
_root.nextFrame();

}

black
09-12-2002, 02:22 AM
Originally posted by apprentice
please add _root before all of your who like this~ ;)

onClipEvent(keyDown) {
if(Key.isDown(65)){
_root.who=1;
_root.buzz.gotoAndStop(2);
_root.whobuzzed.gotoAndPlay("p1");
}
else if(Key.isDown(76)){
_root.who=2;
_root.buzz.gotoAndStop(3);
_root.whobuzzed.gotoAndPlay("p2");
}
_root.nextFrame();

}

apprentice
09-12-2002, 05:43 PM
Thanks, black. I'll give it a shot. ("scratching my head, could it be that simple?")