Local variables inside events is something I was unaware was necessary, nor did the tutorial I was using mention this. The JSON path is also straight from the tutorial, so I am doubly annoyed that it's wrong there too.
In this case the local variable needs to be inside the function, otherwise two functions will be changing it and the result may be incorrect.
Also I think (Variable-1) as a return result is wrong, it needs to be just Variable.
By the way, you can use JSON.ArraySize("Scene") expression instead of those functions. This will return the number of records in the "Scene" array in JSON.
Same for the number of dialogues:
JSON.ArraySize("Scene."& curScene & ".Dialogue")
Layer names in the events were always red, so I went with numbers since the software itself says you can use them- is that not the case?
Layer name as any other strings in events needs to be in double quotation marks:
Set layer "Dialogue" visible
If you decide to add a new layer tomorrow, you will have to update layer numbers throughout your code. With layer names you won't have this problem.