We have an experiment that is supposed to blank all letters out except for a target, and on pressing space it moves along one:
So, say the phrase was hello, there.
Item 1 would be h-----------
Item 2 would be -e----------
item 3 would be --l----------
etc
We have working Python code that used enumeration and then had to rewrite it in Javascript because auto-js didn’t convert the logic correctly, however, it ends up producing completely different results;
item 1 would be: Hello,
item 2 would be: there
In other-words the letter replacement no longer works. However i am not able to figure out why the behaviour has changed even though the logic in the code is now identical. There were also some odd quirks that i don’t understand where one variable defined in python within start routine (SentenceList = trial_text.text.split()) stopped working with JS unless it was moved into the start frame.
The code is:
Start of experiment. Used to create the replacement of the code
function *enumerate(array) {
for (let i = 0; i < array.length; i += 1) {
yield [i, array[i]];
}
}
var replaceWithDash = function(WordList, currentWordNumber) {
let dashSentence = ‘’;
for (let [j, item] of enumerate(WordList)) {
if (j != currentWordNumber) {
dashSentence = dashSentence + “-”.repeat(item.length) + " ";
} else {
dashSentence = ’ ’ + dashSentence + item + ’ ';
}
}
return dashSentence.trim();
}
Start of frame: Create list of test stimuli and then get response
var SentenceList = trial_text.text.split(",");
let theseKeys = psychoJS.eventManager.getKeys();
if (theseKeys.length > 0) { // at least one key was pressed
textAdd = theseKeys[theseKeys.length-1];
if(theseKeys.includes(“space”)){
thisResponseTime = t;
wordNumber = wordNumber + 1;
if(wordNumber < SentenceList.length){
if(wordNumber == 0){
timeOfLastResponse = 0;}
psychoJS.experiment.addData('RT_' + wordNumber, thisResponseTime - timeOfLastResponse);
timeOfLastResponse = thisResponseTime;
trial_text.text = replaceWithDash(SentenceList, wordNumber);
}else{continueRoutine = false;}
}else if ("escape" in theseKeys) {
core.quit();}
}