Is this valid?

Hello,

I’m working on a puzzle-type experience for my students and am trying to check if the value of 4 variables is true. I am using this statement :

if (currentface1==1 && currentface2==1 && currentface3==1 && currentface4==1) {

The scripter doesn’t give me any error, but when I test it, the condition is never true, even when all he values are 1.
Could anyone spot what I’m doing wrong?

Thank you so much :slight_smile:

Ok, figured out my mistake. I was assigning the currentfaceX values taken from root startup script BEFORE pointerdown event, but this wasn’t assigning the value to my local variables. This now works :

parent.on(“pointerdown”, (e) => {

let currentface1=symbol.nodes.startup.face1;
let currentface2=symbol.nodes.startup.face2;
let currentface3=symbol.nodes.startup.face3;
let currentface4=symbol.nodes.startup.face4;

Instr.visible(false);
Check_Btn.visible(false);
Check_Btn.enabled(false);

if (currentface1==1 && currentface2==1 && currentface3==1 && currentface4==1) {

Leaving this here in case it could help someone with a similar problem :slight_smile:

2 Likes

Well done for figuring it out!

Initialization of script nodes currently happens from top-to-bottom in the hierarchy, so if your root startup script was before the one containing the pointerdown event then it would likely have worked in your first version. The typescript checking we do in the editor view isn’t aware of these intialization-order issues, hence why you did not see any errors.

You can add initialization code in a parent.one('ready', ...); handler which will run once, but it is guaranteed at that point that all the script nodes will have been initialized. If some variables in script A depend on some other initialization code in script B then the best route would be to export a function in B to do the initialization, and then call from A before looking at the values of those variables.

1 Like

Hello Tom
I am trying to find some clues on how to achieve this simple puzzle game


But I am having a hard time to find a tutorial or some walkthrough.
The best lead I have is your post here.
Can you please help me to find out how to do please ?
Or something that can get me close to it please ?
Thank you very much.
1 Like