# CSD Game project Help

**URL:** https://forum.code.org/t/csd-game-project-help/37309
**Category:** Coding and Debugging Help
**Created:** [December 2, 2022, 2:11pm UTC](https://forum.code.org/t/csd-game-project-help/37309 "2022-12-02T14:11:01Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![langilla1](https://avatars.discourse-cdn.com/v4/letter/l/f475e1/32.png) [@langilla1](https://forum.code.org/u/langilla1)
#### Post date: [December 2, 2022, 2:11pm UTC](https://forum.code.org/t/csd-game-project-help/37309/1 "2022-12-02T14:11:02Z")

</div>

My student wants the code if (keyDown(“space”)) {  
game();  
} to stay at the game but when you let up on the space key it goes back to the original.

> **[Check out what I made](https://studio.code.org/projects/gamelab/Vz_9UoDUABaELI4nDKZqFfkBIriXVD926hqBGfAgXPA)**
>
> I wrote the code myself with Code.org

---

<div class="post-metadata">

### Author: ![pluto](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/pluto/32/9141_2.png) [@pluto](https://forum.code.org/u/pluto)
#### Post date: [December 2, 2022, 3:14pm UTC](https://forum.code.org/t/csd-game-project-help/37309/2 "2022-12-02T15:14:03Z")

</div>

To fix this issue, you must create a global variable with any name you want. This will store the data that the spacebar has been held down.

```auto
var screen = "Start"

```

When the key is down, you should change the value of the variable to anything you want, but for this example, I will therefore use “Game”.

```auto
if (keyDown("space")) {
 screen = "Game";
}

```

The function will be called **when** it checks the value with an equality operator, then you can call the function in.

```auto
if (screen == "Game") {
 game();
}

```

I hope your student does well!  
If you didn’t understand what I just did, here is a remix when it’s fixed.  
I have it marked with comments blocks so that you can see what I have changed.

> **[Check out what I made](https://studio.code.org/projects/gamelab/JGj0CTOBuK23V8DAMxB4M-HsjivkVrRURnzWjp2Z-Rs/view)**
>
> I wrote the code myself with Code.org

---

<div class="post-metadata">

### Author: ![islanderjourney](https://avatars.discourse-cdn.com/v4/letter/i/f04885/32.png) [@islanderjourney](https://forum.code.org/u/islanderjourney)
#### Post date: [December 2, 2022, 6:08pm UTC](https://forum.code.org/t/csd-game-project-help/37309/3 "2022-12-02T18:08:02Z")

</div>

This is a good solution, but a simpler one would be to just change it from keyDown to keyWentDown. Remember, keyDown is only while the key indicated is actually being held down.

---

<div class="post-metadata">

### Author: ![pluto](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/pluto/32/9141_2.png) [@pluto](https://forum.code.org/u/pluto)
#### Post date: [December 4, 2022, 8:12pm UTC](https://forum.code.org/t/csd-game-project-help/37309/4 "2022-12-04T20:12:04Z")

</div>

Yes I know, but I wasn’t sure if I should change something that wasn’t the actual problem you mentioned.
