"Run if" from OpenSesame to JATOS
Hello! I'm a M1 student and I'm very new to OpenSesame and JATOS.
I'm creating an experiment where participants contribute with tokens. In short, if they reach a total contribution of 30 they win, if not they lose. I put a condition on the display of a "winning sketchpad" and a "losing sketchpad". And it is working on OpenSesame on my computer. But when I run it on a browse the condition is not taken into account anymore (although I do not have any error message).
Here are captures from OpenSesame:
I get at some point that there is a different between inline_script and inline_javascript. I tried to modify the script as follow, but it didn't work either:
set flush_keyboard yes
set description "Lance un certain nombre d'éléments en séquence"
run Contributions_eng_sketchpad True
run Contribution_form_text_input True
run Win_sketchpad vars.get('total') + vars.get('contribution') >= 30
run Lose_sketchpad vars.get('total') + vars.get('contribution') < 30
run Again_eng_form_text_display True
run Experiment_logger True
How can I modify my experiment in order for it to work?
Thanks in advance for any help!
Comments
Hi @MelieMeric,
I'm a little puzzled by your attempt to edit the sequence script. You shouldn't modify it, whether you're running your task in OS or in the browser.
You'd only use Javascript in inline:Javascript objects, not in the script of sequences.
The initial problem you describe may have to do with the way in which the "Run if" condition is parsed when the task runs under Javascript in the browser. Try using a simpler condition (with only one term) just to see if it then gets processed correctly in the browser. If it does, then the problem may have to do with the use of the summation as part of the condition. You might want to try surrounding it with parentheses.
Perhaps you can upload a stripped down version of your task to the forum?
Best,
Fabrice.
Hello Fabrice,
Thank you for your answer. Indeed with a simpler condition it works in the browser. I tried to put parentheses on the condition: it works with OpenSesame but still not in the browser (I tried also brackets but then nothing works).
I am thinking then about creating a variable which would take the value of total+contribution, so that I would have the condition only with it. But I don't know how to do it or where to create it since I don't want it to be displayed, and I don't manage to find documentation on how to do that (I tried on my own, but it was not concluent...)
Here is a stripped down version of my experiment: https://we.tl/t-U3KNbnT0PP
(I didn't manage to upload directly my file on the forum, I got a message error saying that it is too heavy, so I created a WeTransfer link, sorry)
Best,
Melie
Hi @MelieMeric,
Thanks for sending a stripped down version of your task. That's been quite helpful.
Ok, so we have established that the issue relates to the parsing of the condition under the "Run if" parameter when the experiment is running in OSWeb. That's issue 1.
This can be easily solved by injecting some Javascript code just before the Win_sketchpad and Lose_Sketphad, to create a new variable adding up
totalandcontribution(you were on the right track there). This is done by inserting an inline_javascript object before these sketchpads and inserting this code the run tab of the inline_javascript object:This creates a variable (that will show up in the data log) in which we add up the total and the contribution. You can choose to call this variable as you please.
Note that I'm adding
vars.totalandparseInt(vars.contribution). This is becausetotalis a numerical variable, butcontributioncomes from a text box and so is treated as an alphanumerical string even if the subject's response is a number (at least in OSWeb; I think that under Python it might recognize it as a number). So, if one of the two variables is treated as a string and you add it to one that is numerical, Javascrupt treats both as alphanumerical. That means that iftotalis 20 andcontributionis 30,vars.total + vars.contributionreturns "2030" and not "50". So we need to tell Javascript to transform contribution into an integer value (hence the use of the parseInt function).You can download the fixed stripped down version of your task here.
One more observation...
I also noticed that your text is sometimes a little obstructed by the text box on your forms. Modifying the script doesn't seem to fix under OSWeb (while it works under a Python implementation). In your case, removing the empty lines of text makes everything visible. However if you wanted to have more control over the placement of text etc., you could possibly envisage using the inline_html object and write html / javascript code to create your form.
Alternatively, you could also use a multiple keyboard inputs strategy to have the participant type digits and then hit enter to validate their response while updating their response on the screen. This is a little different from how you have implemented it but can be useful in some cases. It is more demanding in terms of programming but it can give you more flexibility. Here is a demonstration of the method we used in another case, just to illustrate the method in case you might be interested to use it in the future:
One advantage of that method is that you could make sure that participants introduce numerical values only. At the moment, in your task as I modified it, if the participant typed "30r" as the contribution, the code would work:
parseInt(contribution)would be 30. But if the participant accidentally started their response with an alphanumerical character (e.g., "r30"),parseInt(contribution)would be "Nan" and so wouldvars.total + parseInt(contribution). If you think this might be an issue, you could address it by inserting your Contributions_eng_sketchpad and Contribution_form_text_input into their own sequence, itself places into a loop, all within your game_sequence. You could then use some Javascript to test whether the value entered is numerical, and base on that change the value of a test variable that you'd use in the "Break if" paramater of that loop within the loop. The result would be that if the participant introduced an alphanumerical response, he/she would be asked to reintroduce their response (until it is validated as a numerical response, at which point that loop would be interrupted and the task would move on).Hope this helps.
Best,
Fabrice.
Hello,
Thank you so much Fabrice! It is perfectly working now. And I needed it to be working for this week-end, so you are a life savior!
I managed to deal with the text being hidden by the text form by playing with the font size and by shortening some sentences. I won't have time to change much things now, but I will definitly take a look at what you sent for next time.
Again, thank you so much for taking the time to look into all of that.
Best,
Melie
Hi @MelieMeric,
Great, I'm glad I could help!
Many thanks for the ☕!
Best,
Fabrice.