Forum Discussion
JavaScript API
- 2 months ago
For your stated issue, you need to change the value in the third trigger on layer q5 to "Q5" instead of "q5" for Set currentQuestion. That fixes the key response.
Unrelated, but you are also missing a T/F SL variable "Q4Correct".
Another note is that in the second trigger JavaScript, for case 'Q5' you could change event.code to event.key just to be consistent with the other keypress checks. It doesn't change anything as the code and key for Pause are the same, but it makes the code clearer.
Your code more or less works to recognize the keys and send variable updates to SL. However, all the key checks are done and the all the SL variables are set no matter what key is pressed (any key). It would help if the event handler knew what question you were on (1 to 4). Maybe set a variable that it can read to tell it which question you're on so it knows which key to check for, and ignore setting the incorrect status for the other questions.
I assume you are making the state changes with a trigger inside SL according to the Pressed and Incorrect variables for each question. Although the JS API provides a way to request state changes from inside a script, it does not work properly on states containing images. The initial image will remain no matter what state you request, so keep that in mind.
Well darn if it won't do state changes for images. Maybe if I do layers like I did with the hints. Thanks Nathan_Hilliard
Related Content
- 3 months ago
- 3 years ago