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

Game breaks after first play?

Explorer ,
May 17, 2013 May 17, 2013

I don't really understand how this happens, but after you run my game once, on any difficulty, it won't work right again. What is supposed to happen, when you enter the game, it sets a variable to true. Then when you click your button, it starts the game. That works for the first run only.

If you run it again (by clicking the main menu button and starting the game on a different difficulty) the game instantly starts.

I can't seem to figure out how this happens, but here's my code:

import flash.events.Event;

import flash.utils.Timer;

import flash.events.MouseEvent;

stop();

var allowBegin:Boolean = false;

var clickCheck:Boolean = false;

var compWin:Boolean = false;

var playerWin:Boolean = false;

var playerNum:int = 0;

var compNum:int = 0;

clickMe.addEventListener(MouseEvent.MOUSE_DOWN, addPlayerHit);

clickMe.addEventListener(MouseEvent.MOUSE_UP, resetClick);

stage.addEventListener(MouseEvent.MOUSE_DOWN, allowStart);

compClock.addEventListener(TimerEvent.TIMER, computerFunct);

mcCompArm.gotoAndStop(1);

clickMe.gotoAndStop(1);

compClick.gotoAndStop(1);

btn_gameOver.visible = false;

setDiff();

function allowStart(Mouse:Event):void

{

          allowBegin = true;

          stage.removeEventListener(MouseEvent.MOUSE_DOWN, allowStart);

          stage.addEventListener(MouseEvent.MOUSE_DOWN, startTimer);

          trace("Used");

}

function computerFunct(e:TimerEvent):void

{

          addCompHit();

    compClock.reset();

          compClock.start();

}

function startTimer(Mouse:Event):void

{

          if(allowBegin == true){

                    compClock.start();

                    allowBegin = false;

          }

}

function addPlayerHit(Mouse:Event):void

{

          if( playerNum < 100 && clickCheck == false){

                    playerNum++;

                    playerCounter.counterText.text = String(playerNum);

                    clickMe.gotoAndStop(2);

                    clickCheck = true;

          }else if(playerNum == 99 && clickCheck == false && playerWin == false && compWin == false)

          {

                    setDiffBeat();

                    playerCounter.counterText.text = "WIN";

                    compCounter.counterText.text = "LOS";

                    endGame();

          }else if (compWin == true){

                    setDiffLost();

                    playerCounter.counterText.text = "LOS";

                    compCounter.counterText.text = "WIN";

                    endGame();

          }

}

function resetClick(Mouse:Event):void{

          if(clickCheck == true){

                    clickMe.gotoAndStop(1);

                    clickCheck = false;

          }

}

function addCompHit():void

{

          if( compNum < 100 && playerWin == false){

                    compNum++;

                    compCounter.counterText.text = String(compNum);

          }else if(compNum == 100 && playerWin == false && compWin == false)

          {

                    setDiffLost();

                    playerCounter.counterText.text = "LOS";

                    compCounter.counterText.text = "WIN";

                    endGame();

          }else if (playerWin == true){

                    setDiffBeat();

                    playerCounter.counterText.text = "WIN";

                    compCounter.counterText.text = "LOS";

                    endGame();

          }

}

function endGame():void

{

          clickMe.removeEventListener(MouseEvent.MOUSE_DOWN, addPlayerHit);

          clickMe.removeEventListener(MouseEvent.MOUSE_UP, resetClick);

          compClock.removeEventListener(TimerEvent.TIMER, computerFunct);

          stage.removeEventListener(MouseEvent.MOUSE_DOWN, allowStart);

          stage.removeEventListener(MouseEvent.MOUSE_DOWN, startTimer);

          btn_gameOver.addEventListener(MouseEvent.MOUSE_DOWN, resetGame);

          compClick.gotoAndStop(1);

          mcCompArm.gotoAndStop(1);

          compWin = true;

          allowBegin = false;

          btn_gameOver.visible = true;

}

function resetGame(Mouse:Event):void

{

          allowBegin = false;

          clickCheck = false;

          compWin = false;

          playerWin = false;

          playerNum = 0;

          compNum = 0;

          allowBegin = false;

          btn_gameOver.visible = false;

          btn_gameOver.removeEventListener(MouseEvent.MOUSE_DOWN, resetGame);

          gotoAndStop("menu");

}

and some more here:

import flash.text.TextFormat;

var difficulty:String = "";

var compClock:Timer=new Timer(999);

var diffBeat:Array = ["no", "no", "no", "no", "no", "no"];

var beatText:TextFormat = new TextFormat();

beatText.color = 0x00FF22;

var lostText:TextFormat = new TextFormat();

lostText.color = 0xFF0022;

function setDiff():void

{

          switch(difficulty){

                    case "superEasy":

                              compClock.delay = 500;

                    break;

                    case "easy":

                              compClock.delay = 400;

                    break;

                    case "normal":

                              compClock.delay = 250;

                    break;

                    case "hard":

                              compClock.delay = 170;

                    break;

                    case "superHard":

                              compClock.delay = 120

                    break;

                    case "impossible":

                              compClock.delay = 60;

                    break;

                    default:

                              compClock.delay = 900;

                              trace("Error");

                    break;

          }

}

function setDiffBeat():void

{

          switch(difficulty){

                    case "superEasy":

                              diffBeat[0] = "yes";

                    break;

                    case "easy":

                              diffBeat[1] = "yes";

                    break;

                    case "normal":

                              diffBeat[2] = "yes";

                    break;

                    case "hard":

                              diffBeat[3] = "yes";

                    break;

                    case "superHard":

                              diffBeat[4] = "yes";

                    break;

                    case "impossible":

                              diffBeat[5] = "yes";

                              trace("Beat");

                    break;

          }

}

function showDiffBeat():void

{

          if(diffBeat[0] == "yes"){

                    supEasy_txt.setTextFormat(beatText);

          }

          if(diffBeat[1] == "yes"){

                    easy_txt.setTextFormat(beatText);

          }

          if(diffBeat[2] == "yes"){

                    norm_txt.setTextFormat(beatText);

          }

          if(diffBeat[3] == "yes"){

                    hard_txt.setTextFormat(beatText);

          }

          if(diffBeat[4] == "yes"){

                    supHard_txt.setTextFormat(beatText);

          }

          if(diffBeat[5] == "yes"){

                    impossible_txt.setTextFormat(beatText);

                    trace("Added");

          }

          if(diffBeat[0] == "lost"){

                    supEasy_txt.setTextFormat(lostText);

          }

          if(diffBeat[1] == "lost"){

                    easy_txt.setTextFormat(lostText);

          }

          if(diffBeat[2] == "lost"){

                    norm_txt.setTextFormat(lostText);

          }

          if(diffBeat[3] == "lost"){

                    hard_txt.setTextFormat(lostText);

          }

          if(diffBeat[4] == "lost"){

                    supHard_txt.setTextFormat(lostText);

          }

          if(diffBeat[5] == "lost"){

                    impossible_txt.setTextFormat(lostText);

          }

}

function setDiffLost():void

{

          switch(difficulty){

                    case "superEasy":

                              diffBeat[0] = "lost";

                    break;

                    case "easy":

                              diffBeat[1] = "lost";

                    break;

                    case "normal":

                              diffBeat[2] = "lost";

                    break;

                    case "hard":

                              diffBeat[3] = "lost";

                    break;

                    case "superHard":

                              diffBeat[4] = "lost";

                    break;

                    case "impossible":

                              diffBeat[5] = "lost";

                    break;

          }

}

TOPICS
ActionScript
1.0K
Translate
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 ,
May 17, 2013 May 17, 2013

which button is clicked to restart the game?

what's supposed to happen when that button is clicked?

Translate
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 ,
May 17, 2013 May 17, 2013

this is the function called to reset the game:

function resetGame(Mouse:Event):void

{

          allowBegin = false;

          clickCheck = false;

          compWin = false;

          playerWin = false;

          playerNum = 0;

          compNum = 0;

          allowBegin = false;

          btn_gameOver.visible = false;

          btn_gameOver.removeEventListener(MouseEvent.MOUSE_DOWN, resetGame);

          gotoAndStop("menu");

}

and it's being used/called by btn_gameOver, which only show's up when the game ends.

Translate
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 ,
May 17, 2013 May 17, 2013

instead of the game instantly starting when btn_gameOver is clicked, what's supposed to happen?

and, do you have code on more than one timeline and/or frame?

Translate
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 ,
May 17, 2013 May 17, 2013

Yeah I have some code that is on all 5 frames, but it's just one long keyframe. It's the second set of code that's posted above.

And the game isn't supposed to start when btn_gameOver is clicked. That takes you back to the main menu. You're supposed to be able to start the game as soon as you click anywhere on the stage after entering. But it starts instantly after you've played once through.

Translate
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 ,
May 17, 2013 May 17, 2013

what code is attached to the "menu" keyframe?

Translate
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 ,
May 25, 2013 May 25, 2013

That would be this code here:

import flash.events.Event;

import flash.filters.*;

var myGlow:GlowFilter = new GlowFilter();

myGlow.inner=false;

myGlow.color = 0x0000FF;

myGlow.blurX = 10;

myGlow.blurY = 10;

stop();

howTo_txt.addEventListener(MouseEvent.MOUSE_OVER, addGlow);

play_txt.addEventListener(MouseEvent.MOUSE_OVER, addGlow);

lvlSel_txt.addEventListener(MouseEvent.MOUSE_OVER, addGlow);

howTo_txt.addEventListener(MouseEvent.MOUSE_OUT, removeGlow);

play_txt.addEventListener(MouseEvent.MOUSE_OUT, removeGlow);

lvlSel_txt.addEventListener(MouseEvent.MOUSE_OUT, removeGlow);

howTo_txt.addEventListener(MouseEvent.MOUSE_DOWN, targ);

play_txt.addEventListener(MouseEvent.MOUSE_DOWN, targ);

lvlSel_txt.addEventListener(MouseEvent.MOUSE_DOWN, targ);

function addGlow(a:Event):void

{

          a.target.filters = [myGlow];

}

function removeGlow(b:Event):void

{

          b.target.filters = [];

}

function removeListeners():void

{

howTo_txt.removeEventListener(MouseEvent.MOUSE_OVER, addGlow);

play_txt.removeEventListener(MouseEvent.MOUSE_OVER, addGlow);

lvlSel_txt.removeEventListener(MouseEvent.MOUSE_OVER, addGlow);

howTo_txt.removeEventListener(MouseEvent.MOUSE_OUT, removeGlow);

play_txt.removeEventListener(MouseEvent.MOUSE_OUT, removeGlow);

lvlSel_txt.removeEventListener(MouseEvent.MOUSE_OUT, removeGlow);

howTo_txt.removeEventListener(MouseEvent.MOUSE_DOWN, targ);

play_txt.removeEventListener(MouseEvent.MOUSE_DOWN, targ);

lvlSel_txt.removeEventListener(MouseEvent.MOUSE_DOWN, targ);

}

function targ(c:MouseEvent):void

{

          switch(c.target)

          {

                    case howTo_txt:

                              removeListeners();

                              gotoAndStop("how");

                    break;

                    case play_txt:

                              removeListeners();

                              difficulty = "superEasy";

                              gotoAndStop("game");

                    break;

                    case lvlSel_txt:

                              removeListeners();

                              gotoAndStop("diff");

                    break;

          }

}

Edit: I think I've edited/changed/optimized the code since last time I posted.

Translate
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 ,
May 25, 2013 May 25, 2013

it looks like that code is designed to start the game if lvlSel_txt is clicked.  why do you say it should start if you click anywhere after the "menu" frame plays?

Translate
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 ,
May 25, 2013 May 25, 2013

Well if you click play_txt it will go to the game and the game has the difficulty set to superEasy.

What I meant was. After you go to the actual game (contained on the frame "game") listeners are set for on the stage, and on the first click it's supposed to set up more listeners for the the computer (Challenger in the game) to actually start playing.

Translate
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 ,
May 25, 2013 May 25, 2013
LATEST

before you go to the "game" frame, you go to the "menu" frame, correct?

if yes, does play_txt work correctly and take you to the "game" frame (where you have a problem)?

Translate
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