blocks = [["Practice",10,0,"The following block contains 10 practice trials. Please press the 'N' key when a non word is presented, press the 'W' key when a word is presented."]]
pmblocks = [["Focal",95,5,"Instruct Focal"],["Non-Focal",95,5,"Instruct Non-Focal"]]
shuffle(pmblocks)
blocks.append(pmblocks[0])
blocks.append(pmblocks[1])
The Auto->JS gives
blocks = [["Practice", 10, 0, "The following block contains 10 practice trials. Please press the 'N' key when a non word is presented, press the 'W' key when a word is presented."]];
pmblocks = [["Focal", 95, 5, "Instruct Focal"], ["Non-Focal", 95, 5, "Instruct Non-Focal"]];
shuffle(pmblocks);
blocks.append(pmblocks[0]);
blocks.append(pmblocks[1]);
This gives an error TypeError: blocks.append is not a function
I’ve used .append earlier in the experiment, so if this error is the first one it encounters then it must be something specific about this way of using it.
@wakecarter, looks like an auto-translation error, since append is not an array method in JS. The equivalent in JS is the push method. @jon will know a bit more about how the auto-translate features will be improved in future but for now, I would suggest some post translation editing, by setting the code type to “Both” after entering the Python code.
I’ve just started a crib sheet in Google docs to collate code that needs to be translated manually. If anyone has anything to add, please add a comment to the document. Otherwise it will grow organically as I translate my own code.
@wakecarter, a solution that allows append to be used in the code components is to add the Array push method to the Array prototype / base class in the Begin Experiment code tab.
That’s great news and will save me a lot of frustration (either repeatedly changing array to push or forgetting that my code component is now both not auto)
Instead of python append function. In the code component if I add this to Begin Experiment* , I should set it to both first and then add this code to js section ? Then later on in js section can i use append or do I use push() ?
As per my crib sheet I strongly recommend having a JS only code component called code_JS in your first routine where you place functions and definitions like this (copy and pasted from my crib sheet ÂŁ. This then allows you to use .append and other Python functions in Auto translation components later