Custom plug-in: proper way to call JavaScript function for display #1986
-
What is the proper way to call a JavaScript function for the content I want to display? I am new to jspsych so wanted to check on the proper way to do this. I looked at a few of the existing plug-ins but didn't see an example of this. I have made a custom plug-in to run my canvas game which is in a JavaScript function called startGame(). If I do: My game displays but underneath it says "undefined". When I inspect the element, it looks like:
Obviously I'm doing something wrong for "undefined" to be displayed to the screen. If I don't set display_element.innerHTML and just call Thank you! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi @amandajemerson, there's really no one way to modify the display - you can write a plugin that changes the page content however you like! You're right that many plugins change the display using It sounds like your And just in case this isn't already clear: the reason why I hope this helps. Let us know if you have any other questions. |
Beta Was this translation helpful? Give feedback.
Hi @amandajemerson, there's really no one way to modify the display - you can write a plugin that changes the page content however you like! You're right that many plugins change the display using
display_element.innerHTML = 'some HTML-formatted string'
, and there are some plugins that create HTML elements via JavaScript functions and then add those to the page with functions likeappend
,insertBefore
etc.It sounds like your
startGame
function handles the display changes itself, which is totally fine! So you can just callstartGame()
on it's own inside yourplugin.trial
function, as you're doing now. If you're curious, you could look at the code for this function to see exactly how it ch…