# Weird Game Glitch O.o

**URL:** <https://forum.kirupa.com/t/weird-game-glitch-o-o/328736>\
**Category:** flash\
**Created:** [June 12, 2012, 2:31am UTC](https://forum.kirupa.com/t/weird-game-glitch-o-o/328736 "2012-06-12T02:31:05Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ragnoroct](https://avatars.discourse-cdn.com/v4/letter/r/f07891/32.png) [@Ragnoroct](https://forum.kirupa.com/u/Ragnoroct)\
**Post date:** [June 12, 2012, 2:31am UTC](https://forum.kirupa.com/t/weird-game-glitch-o-o/328736/1 "2012-06-12T02:31:05Z")

</div>

Ok, so this has me completely baffled. I have the code all set up so if the character is hit. game over is displayed and if you click a button it restarts. The problem is when it restarts the character is sometimes randomly not added to the stage… the character object isn’t null though… \>.\> The program doesn’t identify any game errors.

If he gets hit this code is called

```auto
public function endGame()
        {
            gameOver = true;
            projectileList = null;
            mcBob.deleteBob();
            trace("game over");
            myNewTimer.stop();
            removeChild(mcBoundry);
            removeChild(mcBackground);
            stage.removeEventListener(KeyboardEvent.KEY_DOWN, keyDown);
            stage.removeEventListener(KeyboardEvent.KEY_UP, keyUp);
            resetGame();

        }

```

that calls this function

```auto
private function resetGame()
        {

            myFormat = new TextFormat();
            myFormat2 = new TextFormat();
            myFont = new Font1();
            instrText = new TextField();
            gameOverText = new TextField();
            myFormat2.font = myFont.fontName;
            myFormat2.size = 15;
            myFormat.font = myFont.fontName;
            myFormat.size = 54;
            instrText.embedFonts = true;
            instrText.defaultTextFormat = myFormat2;
            instrText.text = "press any button to restart";
            instrText.x = 179;
            instrText.y = 268;
            instrText.width = 400;
            instrText.height = 100;
            instrText.selectable = false;
            gameOverText.embedFonts = true;
            gameOverText.defaultTextFormat = myFormat;
            gameOverText.text = "game over";
            gameOverText.x = 130;
            gameOverText.y = 173;
            gameOverText.width = 300;
            gameOverText.height = 200;
            gameOverText.selectable = false;
            addChild(gameOverText);
            addChild(instrText);
            stage.addEventListener(KeyboardEvent.KEY_DOWN, restart);

        }

```

which calls this function(kind of resets the game :P)

```auto
private function restart(event:KeyboardEvent)
        {
            stage.removeEventListener(KeyboardEvent.KEY_DOWN, restart);
            stage.focus = stage;
            mcBob = new Bob(285,210);
            addChild(mcBob);
            if (mcBob != null)
            {
                trace(mcBob);
            }
            else
            {
                addChild(mcBob);
            }
            gameOver = false;
            stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDown);
            stage.addEventListener(KeyboardEvent.KEY_UP, keyUp);
            removeChild(instrText);
            removeChild(gameOverText);
            mcBoundry = new Boundry();
            mcBoundry.x = 1.6;
            mcBoundry.y = .4;
            addChild(mcBoundry);
            mcBackground = new Background();
            addChildAt(mcBackground,0);
            projectileList = new Array();
            myTimer = new Timer(333,1);
            myTimer.addEventListener(TimerEvent.TIMER_COMPLETE, startProject);
            myTimer.start();
        }

```

I don’t really get it 😕

but btw this is my first flash game!! 😃

Thanks for the help, you guys rock 🙂
