Page 1 of 1

Faulty execution of JavaScript

PostPosted: Thu Dec 03, 2020 8:17 am
I have a constraint block with code written in JavaScript. That code contains the a statement containing z.charAt(0). When I simulate the block containing the constraint I get the error:

00:00:00,000 WARN: Cannot evaluate. TypeError: z.charAt is not a function

If I type the command z.charAt(0) at the console I get the error:

js>> z.charAt(0) 00:00:00,000 ERROR: ReferenceError: "z" is not defined in <eval> at line number 1 expression body: z.charAt(0)

If I go to the variables tab and expand the constraint block (by that I mean click on the + next to the name of the constraint block) so that the inputs/outputs of the constraint are visible, then the charAt function works:

js>> z.charAt(0)
z.charAt(0) = "N"

Can anybody tell me how to get this to work? For this block, I've also found that I need to include a throwaway line of code at the beginning of the JavaScript. The first line does not seem to execute. Placing something that does nothing useful as a first line makes the second line execute.