# Function wont work

**URL:** https://discourse.processing.org/t/function-wont-work/6134
**Category:** Coding Questions
**Created:** [December 1, 2018, 4:23am UTC](https://discourse.processing.org/t/function-wont-work/6134 "2018-12-01T04:23:37Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![kornFusion](https://avatars.discourse-cdn.com/v4/letter/k/3ec8ea/32.png) [@kornFusion](https://discourse.processing.org/u/kornFusion)
#### Post date: [December 1, 2018, 4:23am UTC](https://discourse.processing.org/t/function-wont-work/6134/1 "2018-12-01T04:23:37Z")

</div>

Hey Everyone,  
I have coded a very simple game which works perfectly except the part where the player loses.  
I have a function called, dead with a condition that if deadSign == true show 2 pictures (PNG)  
which one of the pictures is ReStart icon to basically reset the sketch and go back to the top of the Draw()  
I have upload all the pictures + the sketch in a zip file

[http://www.mediafire.com/file/ie024582qbnaq5y/myGame.zip/file](http://www.mediafire.com/file/ie024582qbnaq5y/myGame.zip/file)

So if you download and play it.you will see the problem.  
just start the game and then click GO - and then do nothing till timer hits 0  
which mean you lose…  
then you see the restart icon there…and you can even click on it…  
but you see the problem…

i would really appreciate your help since im working on this work 2 weeks and cant figure this part out…

---

<div class="post-metadata">

### Author: ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)
#### Post date: [December 1, 2018, 7:18am UTC](https://discourse.processing.org/t/function-wont-work/6134/2 "2018-12-01T07:18:45Z")

</div>

sorry, i not know that game and i not know how to play,  
yes, you put lots of work in it.

your restart after timeout question:  
you must do some reset to return to beginning

```auto
  if ((mouseX>267) && (mouseY>119) && (mouseX<592) && (mouseY<166)) { //StarOver Button
    deadSign = false;
    lvl1 = false;
    lvl1nums = false;
    lvl2 = false;
    lvl2numss = false;
    lvl3 = false;
    lvl3numss = false;
    menu();
  }

```

nevertheless some other things seem to be bad,

try to move the canvas window and you see many other (level pictures ) flicker,  
that means for me that you just draw all levels from start to death over an other  
( well yes you do that in draw )  
but in that functions you not disable them correctly  
like when you check on

> ```
> if (lvl1 == true) {
> 
> ```

check “how long” that { } is, ( by placing the editor cursor behind the {  
it should cover/disable the whole function i think.

---

<div class="post-metadata">

### Author: ![kornFusion](https://avatars.discourse-cdn.com/v4/letter/k/3ec8ea/32.png) [@kornFusion](https://discourse.processing.org/u/kornFusion)
#### Post date: [December 1, 2018, 7:33am UTC](https://discourse.processing.org/t/function-wont-work/6134/3 "2018-12-01T07:33:21Z")

</div>

Thanks buddy,pretty good point…im gonna work on it, will post again…

---

<div class="post-metadata">

### Author: ![akenaton](https://avatars.discourse-cdn.com/v4/letter/a/a88e4f/32.png) [@akenaton](https://discourse.processing.org/u/akenaton)
#### Post date: [December 1, 2018, 10:21am UTC](https://discourse.processing.org/t/function-wont-work/6134/4 "2018-12-01T10:21:50Z")

</div>

@kornFusion===

- as for your start button you have to reset all your booleans to false
- in your code a lot of things are redundant: example in your menu(): you begin to show images then you add an if()…and show two or three of them, which is absolutely useless…
- error line 166 (mouseClicked): if the user in the first level clicks there, it fires the winner level 3 and it s possible that this kind of event happens for other places; you can easily avoid that adding your booleans to the clicks so the user cannot go to the \>level without having won the \<ones.

```auto
if ((mouseX>442) && (mouseY>222) && (mouseX<472) && (mouseY<252) && lvl2winner && lvl1winner) {
    lvl3winner = true;
  }

```

---

<div class="post-metadata">

### Author: ![kornFusion](https://avatars.discourse-cdn.com/v4/letter/k/3ec8ea/32.png) [@kornFusion](https://discourse.processing.org/u/kornFusion)
#### Post date: [December 1, 2018, 5:06pm UTC](https://discourse.processing.org/t/function-wont-work/6134/5 "2018-12-01T17:06:43Z")

</div>

THe reason of redundancy is my stupid brain cant think like a programmer…i should code it like when mouseOver, scale that button.png file … but i couldnt figure it out so i used the stupid way lol

and thanks for pointing out that bug! i just realized those mouseClickes WORK EVERY WHERE!!!  
But i used ur code which worked perfectly…so i have a lead now…

thank youu so much
