PennController for IBEX › Forums › Support › html code with embedded script › Reply To: html code with embedded script
Hi,
You cannot directly send messages to the Logs (or Errors) tab of the Debug window. Your console.log commands will send messages to the javascript console.
Note that neither console.log nor a line appearing in the Logs tab of the Debug window means that the relevant event/value will be logged in the results file.
If you want to save totalCorrect in the results file, you will need to sort of “hack” into how PennController-native elements are handled. In practice, it basically just means adding ._runPromises() after the series of PennController commands (like the code’s already doing with the dummy Button element):
newTrial("headphonecheck", newButton("check", "Start Heaphone Check") .print() , // This Canvas will contain the test itself newCanvas("headphonecheck", 500,500) .print() , // The HeadphoneCheck module fills the element whose id is "hc-container" newFunction( () => getCanvas("headphonecheck")._element.jQueryElement.attr("id", "hc-container") ).call() , getButton("check") .wait() .remove() , // Create this Text element, but don't print it just yet newText("failure", "Sorry, you failed the heaphone check") , newVar("totalCorrect") .global() , // This is where it all happens newFunction( () => { $(document).on('hcHeadphoneCheckEnd', function(event, data) { getCanvas("headphonecheck").remove()._runPromises(); getButton("dummy").click()._runPromises(); getVar("totalCorrect").set( data.data.totalCorrect )._runPromises(); }); HeadphoneCheck.runHeadphoneCheck({totalTrials: 1, trialsPerPage: 1, doCalibration: false // we definitely want to change this for the real one }) }).call() , // This is an invisible button that's clicked in the function above upon success newButton("dummy").wait() ) .log( "totalCorrect" , getVar("totalCorrect") )
Note that you won’t get any reports of totalCorrect in your results file for participants who fail the headphone check, as the experiment will never move to the next trial, so nothing will get sent to the server.
Jeremy