This is part 2 of the tutorial series Learn Javascript in Construct . This picks up from where part 1 left off. So in case you missed it, see Learn Javascript i...
My project contains only an 'On start of layout' event block with "let b = "Hello";" in it but when I run the game, the variable 'b' returns as undefined until I manually declare it in the console.
Is this normal behaviour or am I missing something? This is the case with any variable I make - for some reason I'm not able to declare on runtime through an event block.
To be more specific, the console returns:
"Uncaught ReferenceError: b is not defined
at <anonymous>:1:1"
That's normal - the console basically works in global scope, and it can't access variables declared in other functions (and script blocks in event sheets are actually inside functions), just like how you can't write code in one function that accesses a local variable inside a different function.