psychopy.org | Reference | Downloads | Github

Help with custom code segments

URL of experiment: html/2019 WA v4.js · master · Peter Thwaites / Continuous Word Association - 001 · GitLab

Description of the problem:

Hi all,

I’ve been running this word association experiment for a the past couple of months, and I’m almost done collecting data, but the last few participants are now unavailable for face-to-face sessions so I need to set up online collection. The problem is that some of my code components (mostly timers and text entry) don’t work - presumably because they cannot yet be converted into JavaScript. Could anyone help me with the conversion to JS, or point me in the direction of some instructions that might help? I’m basically a novice coder (I received a lot of help from this forum with the Python code in the experiment, too).

Thanks,

Peter

2019 WA v4.psyexp (21.4 KB)

Hi @Peter_Thwaites, the Each Frame code seems ok, I think taken from the textInput demo or similar, so I will leave that. Here is a translation for each code tab:

////////////////////// Begin Experiment //////////////////////

// Set up a new clock to track word RTs and end the routine 
word_clock = new util.Clock();
type_clock = new util.Clock();

////////////////////// Begin Routine //////////////////////

word_clock.reset();
type_clock.reset();

// update component parameters for each repeat
key_resp = new core.Keyboard();
current_word = '';
stored_words = [];
stored_start_times = [];
stored_submit_times = [];
isFirstKey = true;
modify = false; // track whether the shift key has been pressed.

////////////////////// End Routine //////////////////////

// remember to store any letters typed that weren't terminated 
// with a return key:
if (current_word.length !== 0) {
    stored_words.push(current_word)
}

// save each word in a numbered column:
for (let i = 0; i < stored_words.length; i++) {
  psychoJS.experiment.addData(`typed_word_${i+1}`, word); 
}
// save each word in a numbered column:
for (let i = 0; i < stored_start_times.length; i++) {
  psychoJS.experiment.addData(`start_time_${i+1}`, start_time); 
}

for (let i = 0; i < stored_submit_times.length; i++) {
  psychoJS.experiment.addData(`submit_time_${i+1}`, submit_time); 
}

Hi @dvbridges. Many thanks for this. With these modifications added, the experiment loads successfully but I’m now encountering a new error, which looks like this:

image

It pops up as soon as a key is pressed. Also, if I close the error message, my key presses register onscreen, as they should, but keys such as “backspace” spell out the word “backspace” rather than functioning to delete the previous character, and “Enter” appears to log the word onscreen but then moves forward to the next trial, rather than giving time to input further responses. Do you have any idea how to fix this? I’m working on the first version of the experiment: Peter Thwaites / Continuous Word Association - 001 · GitLab

Thanks again for taking the time,

Peter