# Please help me with this students code-Unit 3 Lesson 22

**URL:** <https://forum.code.org/t/please-help-me-with-this-students-code-unit-3-lesson-22/26122>\
**Category:** CS Discoveries\
**Tags:** csd-unit-3-lesson-22\
**Created:** [April 4, 2019, 5:04pm UTC](https://forum.code.org/t/please-help-me-with-this-students-code-unit-3-lesson-22/26122 "2019-04-04T17:04:46Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![stefaniem](https://avatars.discourse-cdn.com/v4/letter/s/ba8739/32.png) [@stefaniem](https://forum.code.org/u/stefaniem)\
**Post date:** [April 4, 2019, 5:04pm UTC](https://forum.code.org/t/please-help-me-with-this-students-code-unit-3-lesson-22/26122/1 "2019-04-04T17:04:46Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![bradleywellsashley](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/bradleywellsashley/32/522_2.png) [@bradleywellsashley](https://forum.code.org/u/bradleywellsashley)\
**Post date:** [April 6, 2019, 3:11pm UTC](https://forum.code.org/t/please-help-me-with-this-students-code-unit-3-lesson-22/26122/2 "2019-04-06T15:11:20Z")

</div>

Stefanie,

What is this supposed to do/ how can we help. Right now when the user either presses the “1” or “2” a bunch of objects move vertically or horizontally across the screen, which is what the code directs the objects to do. Let us know what the final product is supposed to be and let’s figure this out together!

Brad

---

<div class="post-metadata">

**Author:** ![stefaniem](https://avatars.discourse-cdn.com/v4/letter/s/ba8739/32.png) [@stefaniem](https://forum.code.org/u/stefaniem)\
**Post date:** [April 8, 2019, 1:45pm UTC](https://forum.code.org/t/please-help-me-with-this-students-code-unit-3-lesson-22/26122/3 "2019-04-08T13:45:44Z")

</div>

The number key 1 and 2 trigger two different games. Each time the numbers are pressed, it should reset the game so that the other is not running as well. Game number one is a simple vertical scroller game in which the spaceship “eb” collects a point when touching any cow c1 through c9. The player loses 10 points when touching the “crazy” cow c10. That is as far as it goes. The second game is an extremely simple side scroller in which the dinosaur avoids the cacti obstacle “ob(number)” at all costs using only the x and y axes. It is basically a slightly different version of the dinosaur game that you can play when you do not have internet service on Google. (On a mobile device, I believe.) -Caidan Bevacqua

**Stefanie Morrison**

**Business/Computer Teacher**

**Yearbook Advisor**

**Johnsonburg Area Junior/Senior High School**

**315 High School Road, Johnsonburg PA 15845**

**814-965-2556**

---

<div class="post-metadata">

**Author:** ![edavis](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/edavis/32/4927_2.png) [@edavis](https://forum.code.org/u/edavis)\
**Post date:** [April 10, 2019, 11:32pm UTC](https://forum.code.org/t/please-help-me-with-this-students-code-unit-3-lesson-22/26122/4 "2019-04-10T23:32:14Z")

</div>

Hi @stefaniem,  
I was just checking in to see if you need further help with this project. As it is right now, it looks like it is switching between games very well. Please let us know if you need more help.

---

<div class="post-metadata">

**Author:** ![stefaniem](https://avatars.discourse-cdn.com/v4/letter/s/ba8739/32.png) [@stefaniem](https://forum.code.org/u/stefaniem)\
**Post date:** [April 11, 2019, 12:25pm UTC](https://forum.code.org/t/please-help-me-with-this-students-code-unit-3-lesson-22/26122/5 "2019-04-11T12:25:14Z")

</div>

I do need help, did you remix it? I would appreciate help so much.

**Stefanie Morrison**

**Business/Computer Teacher**

**Yearbook Advisor**

**Johnsonburg Area Junior/Senior High School**

**315 High School Road, Johnsonburg PA 15845**

**814-965-2556**

---

<div class="post-metadata">

**Author:** ![stefaniem](https://avatars.discourse-cdn.com/v4/letter/s/ba8739/32.png) [@stefaniem](https://forum.code.org/u/stefaniem)\
**Post date:** [April 12, 2019, 1:23pm UTC](https://forum.code.org/t/please-help-me-with-this-students-code-unit-3-lesson-22/26122/6 "2019-04-12T13:23:41Z")

</div>

It only switches I am not able to actually play the game. Can you please help me.

**Stefanie Morrison**

**Business/Computer Teacher**

**Yearbook Advisor**

**Johnsonburg Area Junior/Senior High School**

**315 High School Road, Johnsonburg PA 15845**

**814-965-2556**

---

<div class="post-metadata">

**Author:** ![josh](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/josh/32/868_2.png) [@josh](https://forum.code.org/u/josh)\
**Post date:** [April 13, 2019, 3:13am UTC](https://forum.code.org/t/please-help-me-with-this-students-code-unit-3-lesson-22/26122/7 "2019-04-13T03:13:10Z")

</div>

It’s a bit difficult to understand the intent of the code without comments, but it looks like the functions that run each came are only being called a single time becaues they are in `keyWentDown` conditionals (which are only true immediately after you press down the key). A different approach to this problem would be to use a variable to track which game mode you are in. For example

```auto
var game_mode = 0;

if (keyWentDown(1)) {
  game_mode = 1;
}

if (keyWentDown(2)) {
  game_mode = 2;
}

if (game_mode == 1) {
  //do game 1 stuff
} else if (game_mode == 2) {
  //do game 2 stuff
}

```

---

<div class="post-metadata">

**Author:** ![stefaniem](https://avatars.discourse-cdn.com/v4/letter/s/ba8739/32.png) [@stefaniem](https://forum.code.org/u/stefaniem)\
**Post date:** [April 16, 2019, 12:33pm UTC](https://forum.code.org/t/please-help-me-with-this-students-code-unit-3-lesson-22/26122/8 "2019-04-16T12:33:28Z")

</div>

I made the student add comments, would you be able to look at the code again. We appreciate the help [https://studio.code.org/projects/gamelab/Zi\_qIDza5ZTjBnyHOL3uzJEV-gvPy-rGROcTkt7AZQU](https://studio.code.org/projects/gamelab/Zi_qIDza5ZTjBnyHOL3uzJEV-gvPy-rGROcTkt7AZQU)  
Thank you so much for your time.

---

<div class="post-metadata">

**Author:** ![jold](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/jold/32/5811_2.png) [@jold](https://forum.code.org/u/jold)\
**Post date:** [April 16, 2019, 9:25pm UTC](https://forum.code.org/t/please-help-me-with-this-students-code-unit-3-lesson-22/26122/9 "2019-04-16T21:25:52Z")

</div>

I think one of the problems is in the keyWentDown to select the games.  
You only press the 1 or 2 key once. After that you need those branches of code to be executed every time through the game but you can’t keep pressing the 1 or 2 key.  
So I made some variables to control what game you play. When the 1 key goes does it sets the gameOne variable to true and then every time through the draw loop the code for game one get executed. Same for game 2. Check out the structure.

I edited it a bit to get the controls working.  
I’m not sure what the variables x,y, and z control. I commented some of that out.

Check it out.

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

Let us know how it goes.
