My if statements not working

Hey all, we need some help with figuring this out, I have been trying to create an if statement that activates a state after a video has finished I first tried to add a boolean and say if true activate the state however I ran into this problem:
The (Startshalwe === true) is saying its wrong syntax and the === does not go with the true-false statement.

after running this code:

`const display_shown = symbol.controllers.display.elements.shown;
const display_hidden = symbol.controllers.display.elements.hidden;
var Startshalwe = false;

const Sipsmith_Bottle = symbol.nodes.Sipsmith_Bottle;

parent.on(“show”, () => {

// Make sure we start from fully hidden
display_hidden.reset();

// Move to the shown state
display_shown.activate();
console.log(Startshalwe);

Sipsmith_Bottle.nodes.Label1_mp4.start();

Sipsmith_Bottle.nodes.Label1_mp4.on("finish", () => {
    Sipsmith_Bottle.controllers.Picture.elements.Seen.activate();
    Startshalwe = true;
    console.log(Startshalwe);
});

});

if (Startshalwe === true){
symbol.controllers.start.elements.shall_we_show.activate();
console.log(Startshalwe);
};`
…

So I then tried a counter that will be the most helpful for when I reuse the code allowing me to have different things happen to depend on the number of times the video has been finished as I restart it and change the source to other videos playing however now the code says there is nothing wrong but it simply doesn’t work.
I tried console log and the log of the counter after the video has finished doesn’t display.

Here is the code i tried:

`const display_shown = symbol.controllers.display.elements.shown;
const display_hidden = symbol.controllers.display.elements.hidden;
var Startshalwe = 0;

const Sipsmith_Bottle = symbol.nodes.Sipsmith_Bottle;

parent.on(“show”, () => {

// Make sure we start from fully hidden
display_hidden.reset();

// Move to the shown state
display_shown.activate();
console.log(Startshalwe);

Sipsmith_Bottle.nodes.Label1_mp4.start();

Sipsmith_Bottle.nodes.Label1_mp4.on("finish", () => {
    Sipsmith_Bottle.controllers.Picture.elements.Seen.activate();
    Startshalwe++;
    console.log(Startshalwe);
});

});

if (Startshalwe === 1){
symbol.controllers.start.elements.shall_we_show.activate();
console.log(Startshalwe);
};`

to fix the (if true ) just use 1 (=)

if (Startshalwe = true){
symbol.controllers.start.elements.shall_we_show.activate();
console.log(Startshalwe);
};

as for the 2nd one you need to move the

Sipsmith_Bottle.nodes.Label1_mp4.on(“finish”, () => {
Sipsmith_Bottle.controllers.Picture.elements.Seen.activate();
Startshalwe++;
console.log(Startshalwe);
});

to the end. it’s inside the “show” and will not work.

Steve

1 Like

Hi,

if Startshalwe is a boolean: if (Startshalwe == true)… or if(Startshalwe)…
if Startshalwe is a number: if (Startshalwe == 1)…

Also, the if(…) must be inside a handler otherwise it won’t be executed.
In the on.finish() for instance.

Cheers.

2 Likes

Thanks so much @jvouillon and @stevesanerd, super helpful as always.

3 Likes

thank you for the help I just tried it all and its 100% working :slight_smile:

2 Likes