Accessing local variables
A useful way to pass values between scripts and the event sheet is to use local variables in the event sheet. These can be accessed by both script actions and script blocks using the variable name
localVars. This is set to an object with a property for each local variable in scope. The available local variables are the same as are available to a Set value action in the same place. This includes any parameters for event sheet functions.
For example a script in an event group with a local variable named temp can access the local variable using
localVars.temp. A useful pattern is to use an action to set a local variable to an expression, and then read from it in a following script action. Alternatively a script could calculate a value and assign it to a local variable, to subsequently be used in the event sheet. It could also be used both ways at once, both reading the variable and then assigning it.
localVars excludes global variables, which are available via runtime.globalVars instead.
localVars is also unique to scripts in the event sheet - script files cannot access it, because they do not have a scope.
Any exceptions, or rejected promises, arising from a script in an event sheet will be caught by the Construct engine and logged to the console with information about where the error came from. This means unhandled exceptions or rejections will not crash the game (since browsers stop running scripts if they encounter an unhandled error). However you should keep an eye on the browser console to check for any unexpected errors. For more information see the section on debugging script.