Is this valid?


#1

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:


#2

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:


#3

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.


Exporting functions; what am I doing wrong?