Ok, I figured out variable reassignment in JS so now the responses for the participant are resetting. However, the program doesn’t seem to be reading the algorithm properly for the computer the participant plays against. The translation of code Python to JS looks complete so not sure why its not working, I will be working on it.
Hey!
Sorry to be a bother again but I’ve since taken the advice you gave. However when running the experiment it says that it can’t find the variable “ImagePositionX”.
I’ll attach screenshots for reference…
Any advice? 
Have you tried $(ImagePositionX,ImagePositionY) as per my crib sheet?
Yep! I’ve just done that and it runs smoothly on psychopy now, but once uploaded onto pavlovia I get that same message that it’s not defined.
Sorry to bother!
I noticed in your crib sheet you’ve said that when this message is displayed to set a value for “ImagePositionX” in a Begin Experiments code block.
Could you explain how to do this?
Sorry I’m quite unfamiliar with coding etc.
You could just put ImagePositionX = 0 in the Python panel of the Begin Experiment tab of an auto translating code component. However, in your case it may mean that the Excel file isn’t being read properly.
It’s worth a try. You’ll also need to put ImagePositionY = 0
Hey wakecarter, I just wanted to give you an update. I’ve had to put the task to the side this week because I just started a summer class, but hopefully I get to take a look again over the weekend. I really appreciated your help so far and I was wondering if you wouldn’t mind me adding your name in my acknowledgements section a part of my dissertation. I am hoping to publish the data collected from this task at some point as well so I could add you as a co-author to the manuscript down the line too. Thank you once again!
Thank you. In my role as a psychology demonstrator I rarely lead in research projects so I’m very grateful for the opportunity for coauthorships or acknowledgments as appropriate.
I’ve put a list of the acknowledgments I know about on my staff page
https://www.brookes.ac.uk/templates/pages/staff.aspx?wid=&op=full&uid=p0071480
Hey Wake hope you are doing well. I picked up my task again and I’m trying to get the algorithm working which depends on the use of the append function. However I don’t think it is working correctly because the choices of the “computer” don’t adjust for the decison-making of the particpant. Can you check this out and let me know if I converted the append function correctly for JS? Once I enter the the initial conversion from your crib sheet thought I am supposed to use the push function?
The key is to identify at what point it’s failing. For example, you can add print statements into the Python to flag when it is processing the contents of a given conditional statement.
Also, I notice that you have my crib sheet error in code_JS. It should be String.prototype.upper = “”.toUpperCase; not Object.prototype.upper = “”.toUpperCase;.
Also, it looks like ToneAlgorithm must be set to Both since you have .push on the right hand side rather than .append.
Will the print statements reveal errors in JS if they are written in Python code?
I had set ToneAlgorithm to both to change the append function to push function on the JS side, when I close and reopen the component it just automatically return to Auto–>JS but that shouldn’t be an issue.
Print statements auto translate correctly to console log statements in JS.
If you set a component to Both and change the JS it’s fine so long as you don’t touch the Python side. I try to minimise the number of Both components I need through the use of cose_JS and also often put the statements that need manual editing in a separate code component.
Ok that makes sense. I will be defending my dissertation proposal this Friday so the majority of my attention will be directed towards that but I hope to find some time to address this over the week or weekend. I will let you know what happens.
Hey Wake, so I have generated the error statements, however I don’t know where to look for the output to determine where the error occured.
Please post your errors and, if possible, which lines might be causing them.
So no actual error statement is produced when running the experiment through Pavlovia, the task runs through completely. However, the code doesn’t execute the proper commands to generate the choice for the computer in the task, which includes the slicing of list and the use of an integer value to determine the probability of the computer “cooperating” or “defecting”. So when the task runs in Pavolovia, the computer always chooses to cooperate regardless of the participants decision. The task is the prisoner’s dilemma by the way I don’t remember if I have told you. I will attach an image of what the code looks like again. But yes now the problem is since an error statement isn’t produced I can’t tell exactly what is wrong.
This is part of the portion where the computer (player2) should be deciding to cooperate (c) or defect (d). Compcoop is generated using a randint function.
This is the portion where the outcome is generated based on the conjunction of player1 and player2 (computers) responses. Only pay attention to the circled portion. Let me know if you have any questions.
If there’s no error then the likely problem is that one of the variables isn’t behaving as intended. You can track this with print/console log or text components displaying the current value of key variables. From the look of it, the first one to check is compcoop. You could also display player1, player2 and outcomesExc.
Where will the JS output be visible at? When I run the task in PsychoPy I only see the Python-coded variables printed.
Thank you for the Developer Tools tip! So if you take a look at what I have circled here, what I have printing in order is 1) the outcomes array, 2) player1 decision, 3) player2 (computer) decision, and 4) compcoop (probability of computer cooperation). What seems to happen is after the first round, player1’s decision is still logged but player2’s is not. So consequentially, the array is not being appended with the next outcome. Additionally, the outcome is always the first outcome no matter what decision is made by player1 in subsequent rounds. I think this is all happening because the decision portion of the code is not being read correctly by JS, leaving player2 blank after the first round.








