-2

I make a slide puzzle game. When the puzzle is solved "won" should be displayed and the timer should stop.

I hope you can help me. Thanks.

Here is a link to the web editor for my puzzle link

Here is the part of the code but it doesn´t work:

function draw() {
  if (isSolved()) {
    console.log('SOLVED');
    timerValue = 0;
    text('Won', width/2, height/2);
  }   
}

function isSolved() {
  for (let i = 0; i < plate.length - 1; i++) {
    if (plate[i] !== tiles[i].index) {
      return false;
    }
  }
return true;
}
  • 2
    Please give us a reproduceable example! We can't actually begin to solve your problem without assuming a couple of things. It would be helpful to have the array `plate` and the array `tiles` in your question. Once I get those things (or just a link to the web editor) I'll work on a fix. – KoderM May 15 '22 at 20:20
  • @KoderM here is a link to the web editor for the puzzle [link](https://editor.p5js.org/Nightdragon22/sketches/PP9MnmVJG) – Nightdragon22 May 16 '22 at 11:16
  • For your "gameover" statment on line 84. Use `noLoop()` instead of reassigning the `draw` function. But I think the answer is that you aren't swapping the places of the `plate` array along with the `tile` array. – KoderM May 16 '22 at 17:40
  • @KoderM Thank you. I have added `noLoop( )` to my code. – Nightdragon22 May 16 '22 at 17:54

1 Answers1

-1

P5JS is saying that createImage() was expecting Integer for the second parameter, received number instead. This can be solved by changing let img = createImage(w, h); tp let img = createImage(int(w), int(h));.

I'm not entirely sure if this helps, because I don't know how your puzzle works (how it's solved) so please tell me if this doesn't work and I'll investigate further.

Voxel
  • 64
  • 9