[SOLVED] How to go to next frame when variable is equal to certain amount

I am using the 1.19.3 version of wick editor

I’m pretty new to making games on wick editor so I don’t know much.
I am trying to make a game where each time you push the button it makes the score
higher, and when it reaches the score of 50 it goes and stops at the next frame.

I tried using

if (project.score == 50) {
gotoAndStop(2);
}

in the default script of the frame for it to go to the next frame but it doesn’t do anything.


Additional info:

I am using:

project.score += 1;
scoreCounter.setText("Crayfish eaten: " + project.score);

in the mouseclick script of the object for the score to go higher when I click it

and

project.score = 0;
stop()

in the default script of the frame.

[Solved]
I put if (project.score == 50) {
gotoAndStop(2);
} in the update script and added an additional equals sign .

the problem is that it’s in the default script. the default script will only run your if-statement once (at the very start). it’ll be false and that will be it. try to put your if-statement in the update script instead and see if it works.

also, I’m not sure what the difference between == and === is, but generally I use ===. i don’t know which one is better but @Jovanny might be able to shed some light on this.

1 Like

Ohhh I see…
Thanks!

=== vs == is a js thing. In most other languages is == only.

Both have their use cases, but you are right, === should be used more than ==.

The reason is that in js ‘==’ does more checks and castings allowing things like:
‘1’ == 1 -> true
null == 0 -> false
undefined == null -> true
1 == 1 -> true
0 == 0 -> true
While it seems convenient in some cases, performance-wise is a little bit slower.

This is what happens in '==='
‘1’ === 1 -> false
null === 0 -> false
undefined === null -> false
1 === 1 -> true
0 === 0 -> true

Here are some tests:
Screen Shot 2022-05-26 at 12.12.04 PM

1 Like