# All codes seem to be correct, but no response from system

**URL:** <https://discourse.processing.org/t/all-codes-seem-to-be-correct-but-no-response-from-system/29665>\
**Category:** Coding Questions\
**Created:** [April 26, 2021, 9:35pm UTC](https://discourse.processing.org/t/all-codes-seem-to-be-correct-but-no-response-from-system/29665 "2021-04-26T21:35:59Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![JustinChan613](https://avatars.discourse-cdn.com/v4/letter/j/73ab20/32.png) [@JustinChan613](https://discourse.processing.org/u/JustinChan613)\
**Post date:** [April 26, 2021, 9:35pm UTC](https://discourse.processing.org/t/all-codes-seem-to-be-correct-but-no-response-from-system/29665/1 "2021-04-26T21:35:59Z")

</div>

Still working on the tic tac toe, I have almost done the whole coding. Right now I am working on the random picking of players. When even the console.log is working, there is no response from the system. Would like to ask where the problem is? Thanks!

Code: [p5.js Web Editor](https://editor.p5js.org/JustinChan/sketches/kit1YgXsm)

---

<div class="post-metadata">

**Author:** ![jb4x](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jb4x/32/789_2.png) [@jb4x](https://discourse.processing.org/u/jb4x)\
**Post date:** [April 26, 2021, 9:56pm UTC](https://discourse.processing.org/t/all-codes-seem-to-be-correct-but-no-response-from-system/29665/2 "2021-04-26T21:56:52Z")

</div>

Hello Justin,

You have a `noLoop()` in `draw()`, that’s why nothing happens.

That’s not how you want to handle your turn.  
Your draw needs to keep drawing the game, but what needs to be drawn needs to change over time.

For example in the following code, the canvas is constantly drawn. When the mouse is clicked, a new ellipse is created and then displayed in the for loop of the draw() function.

```auto
let ellipses = [];

function setup() {
  createCanvas(400, 400);
  ellipses.push(createVector(20, 20));
}

function draw() {
  background(20);
  noStroke();
  fill(220);

  for (let i = 0; i < ellipses.length; i++) {
    let x = ellipses[i].x;
    let y = ellipses[i].y;
    ellipse(x, y, 10, 10);
  }
}

function mouseClicked() {
  ellipses.push(createVector(mouseX, mouseY));
}

```

---

<div class="post-metadata">

**Author:** ![JustinChan613](https://avatars.discourse-cdn.com/v4/letter/j/73ab20/32.png) [@JustinChan613](https://discourse.processing.org/u/JustinChan613)\
**Post date:** [April 26, 2021, 10:33pm UTC](https://discourse.processing.org/t/all-codes-seem-to-be-correct-but-no-response-from-system/29665/3 "2021-04-26T22:33:27Z")

</div>

Thank you! So what I have to do is only to include the for loop in my function draw( )? Sorry I don’t really get what is going on for the functions.

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [April 27, 2021, 12:10am UTC](https://discourse.processing.org/t/all-codes-seem-to-be-correct-but-no-response-from-system/29665/4 "2021-04-27T00:10:36Z")

</div>

Hello,

These do need to be in each cycle of draw():

```auto
//let players = ['0', '1'];
//let p = random(players);
//noLoop();

```

Add global variables:

```auto
 let players = ['0', '1'];
 let p;

```

setup() runs once so create p there:

```auto
p = random(players);

```

I just took a quick look and got some game play with the changes.

`:)`

References:

- setup() [reference | p5.js](https://p5js.org/reference/#/p5/setup)
- draw() [reference | p5.js](https://p5js.org/reference/#/p5/draw)
- Variable Scope [examples | p5.js](https://p5js.org/examples/data-variable-scope.html)

I added colors and moved text:  
 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/c/ce1ad780cf3f7b3ba949fe7bf7fccbb21c0747f5.png)

---

<div class="post-metadata">

**Author:** ![JustinChan613](https://avatars.discourse-cdn.com/v4/letter/j/73ab20/32.png) [@JustinChan613](https://discourse.processing.org/u/JustinChan613)\
**Post date:** [April 27, 2021, 9:47am UTC](https://discourse.processing.org/t/all-codes-seem-to-be-correct-but-no-response-from-system/29665/5 "2021-04-27T09:47:22Z")

</div>

Thanks! Then I kinda get it. Does it mean that when it is in function setup( ), the p = random(players) apply to every turn of the game, instead of only applying to first turn when it is in function draw( )?
