Running experiments online using OSWeb
Hi,
I have been using Opensesame for several years and it worked really well. I am now trying to run a lexical decision study online, but I had the following error:
uncaught typeerror: cannot read properties of undefined (reading 'apply') see the console for further details
The source of the error seems to be my two in-line scripts: one for recording the handness of participants (so that they pressed the 'yes' button with their dominant hand), the other is to counterbalance.
In-line script 1:
if var.response_handedness_response =='l':
var.y_response='z'
var.n_response='m'
else:
var.y_response='m'
var.n_response='z'
In-line script 2:
if self.get('subject_nr')%8 == 1:
b1 = 0
b2 = 10
b3 = 10
b4 = 10
b5 = 10
b6 = 10
b7 = 10
b8 = 10
elif self.get('subject_nr')%8 == 2:
b1 = 10
b2 = 0
b3 = 10
b4 = 10
b5 = 10
b6 = 10
b7 = 10
b8 = 10
elif self.get('subject_nr')%8 == 3:
b1 = 10
b2 = 10
b3 = 0
b4 = 10
b5 = 10
b6 = 10
b7 = 10
b8 = 10
elif self.get('subject_nr')%8 == 4:
b1 = 10
b2 = 10
b3 = 10
b4 = 0
b5 = 10
b6 = 10
b7 = 10
b8 = 10
elif self.get('subject_nr')%8 == 5:
b1 = 10
b2 = 10
b3 = 10
b4 = 10
b5 = 0
b6 = 10
b7 = 10
b8 = 10
elif self.get('subject_nr')%8 == 6:
b1 = 10
b2 = 10
b3 = 10
b4 = 10
b5 = 10
b6 = 0
b7 = 10
b8 = 10
elif self.get('subject_nr')%8 == 7:
b1 = 10
b2 = 10
b3 = 10
b4 = 10
b5 = 10
b6 = 10
b7 = 0
b8 = 10
b9 = 10
else:
b1 = 10
b2 = 10
b3 = 10
b4 = 10
b5 = 10
b6 = 10
b7 = 10
b8 = 0
exp.set('b1',b1)
exp.set('b2',b2)
exp.set('b3',b3)
exp.set('b4',b4)
exp.set('b5',b5)
exp.set('b6',b6)
exp.set('b7',b7)
exp.set('b8',b8)
I deleted the first online script and changed the second into the following Javascript using an online converter, but I still got the same error message.
var b1, b2, b3, b4, b5, b6, b7, b8, b9;
if (this.get("subject_nr") % 8 === 1) {
b1 = 0;
b2 = 10;
b3 = 10;
b4 = 10;
b5 = 10;
b6 = 10;
b7 = 10;
b8 = 10;
} else {
if (this.get("subject_nr") % 8 === 2) {
b1 = 10;
b2 = 0;
b3 = 10;
b4 = 10;
b5 = 10;
b6 = 10;
b7 = 10;
b8 = 10;
} else {
if (this.get("subject_nr") % 8 === 3) {
b1 = 10;
b2 = 10;
b3 = 0;
b4 = 10;
b5 = 10;
b6 = 10;
b7 = 10;
b8 = 10;
} else {
if (this.get("subject_nr") % 8 === 4) {
b1 = 10;
b2 = 10;
b3 = 10;
b4 = 0;
b5 = 10;
b6 = 10;
b7 = 10;
b8 = 10;
} else {
if (this.get("subject_nr") % 8 === 5) {
b1 = 10;
b2 = 10;
b3 = 10;
b4 = 10;
b5 = 0;
b6 = 10;
b7 = 10;
b8 = 10;
} else {
if (this.get("subject_nr") % 8 === 6) {
b1 = 10;
b2 = 10;
b3 = 10;
b4 = 10;
b5 = 10;
b6 = 0;
b7 = 10;
b8 = 10;
} else {
if (this.get("subject_nr") % 8 === 7) {
b1 = 10;
b2 = 10;
b3 = 10;
b4 = 10;
b5 = 10;
b6 = 10;
b7 = 0;
b8 = 10;
b9 = 10;
} else {
b1 = 10;
b2 = 10;
b3 = 10;
b4 = 10;
b5 = 10;
b6 = 10;
b7 = 10;
b8 = 0;
}
}
}
}
}
}
}
exp.set("b1", b1);
exp.set("b2", b2);
exp.set("b3", b3);
exp.set("b4", b4);
exp.set("b5", b5);
exp.set("b6", b6);
exp.set("b7", b7);
exp.set("b8", b8);
I am now unsure of what to do to solve the error. Do you have any suggestions? Thanks so much in advance!
Comments
Hi @Yuyanxue,
Just a quick comment... Would need to try your program to be sure but it looks like you're trying to use Python code into your Inline_Javascript objects... "this.get" and "exp.set" are Python commands.
To access the subject number in Javascript, use vars.subject_nr. To set a variable's value task-wise, replace exp.set by vars. For example:
exp.set("b1", b1)
becomesvars.b1=b1
.That's my first suggestion anyway. Try it out to see if it helps...
Best,
Fabrice.
PS: please note that it is best to post messages related to OSweb to the OSWeb forum. I'm moving this thread to that forum so that it can benefit other OSWeb users too.
Hi Fabrice,
Thanks a lot for your suggestion. I have replaced exp.set by vars, but the same error occurred. Also, when I tried to run the experiment without the two in-line scripts, another error message occurred:
"Uncaught ReferenceError: Variable 'y_response' not present in var store
See the console for further details".
'y_response' is a variable specified in one of the in-line script, and also in the stimuli table.
I have attached a simpler version of the experiment which only had one trial in each block (four blocks per list). It has two in-line scripts: one is "handedness_script" and the other is "counterbalance". The experiment worked perfectly using Opensesame, but couldn't run in OSWeb.
Could you please help solve the problems?
Thanks a lot,
Mengzhu
Hi @Yuyanxue,
First, many thanks for the ☕️! very nice of you. It's very much appreciated!
Second, just for your information, when addressing messages to specific forum users in the forum, it helps using their handle. You can do so by typing "@" and the first letters of the users name. A pull down menu then appears, which you can use to select the user you're addressing the message to. For example, if I type
@Yu
, the following appears:Using handlers means that your correspondent gets a notification when they visit the forum. As there can be many message posted on the forum, using my handler ensures that I'm more likely to see taht there is a message for me.
Third, moving on to your task... I had a quick look at the task you sent me. I could see that many objects were
inline_script
objects containing Python code. These need to be replaced byinline_Javascript
objects containing Javascript code doing the equivalent of what your Python code was using. Sometimes it is relatively easy, sometimes it is harder (for example when it comes to shuffling an array). You then must make sure to delete theinline_script
objects containing Python code and make sure to permanently erase them from the unused objects (otherwise,, even though you're no longer using these objects, the task will still try to interpret them and the task won't run in a browser).A lot of the rewriting follows the instructions I gave you in my earlier message. That is, instead of using
self.get
, you'd usevars
. So, for example,self.get('subject_nr')
in Python becomesvars.subect_nr
in Javascript.Your
couterbalance
oinline_script
code:... needs to be rewritten in Javascript within an inline_Javascript object. Your original code was quite redundant (all b variables are equal to 10 except one, depending on the subject's number). I simplified it as follows:
The shuffling of the
block_list
array is a little harder because Javascript does not contain an already existing shuffling function. In Python, it is easy to import one ("from random import shuffle"), but in Javascript, you must create and declare such function to then be able to call it. There are various ways to shuffle an array in Javascript. Some are compatible with EC5 and others only with EC6 (see this webpage for a discussion of the difference: https://www.javatpoint.com/es5-vs-es6). As fas as I know, it is best to use methods compatible with EC5 for the moment (as I believe that OSWeb does not yet support EC6).I rewrote your randomisation code into an
inline_Javascript
object as follows:Note: Your task structure is quite complex. I suspect it could be simplified, but this is outside the help I can provide. Seeing that you're using 8 blocks, I did take the liberty of creating a
block_list
array with 8 elements and to create variables L0 to L7. Please revise and modify as needed.This was not enough, however... When testing your task in OSWeb it is important to try it through your browser (making the console visible; CTRL+i, helps tracking what is going on and identify problems, or at least sometimes). Some features of the task worked in OS but not in OSWeb. Such things can be as little as not declaring variables in a way Javascript likes. So, for example,
b1 = 10
will run when the task is executed in OS, but it will generate an error (saying that the variable is not defined when running it in OSWeb). Hence, it needs to bevar b1=10
. Always testing your task through OSWeb as you develop it will help detecting possible problems (if you develop it and test it only through OS, you may then have to do quite a lot of debugging as I had to do with your task).Also, you were also using Python code in the "Run if" conditions of numerous sequences. For example:
Expressions such as self.get are Python instructions. They will work when you run the task in OS:
... but not when you run it through the browser (i.e., when using OSWeb):
So, all of the "run if" conditions need to be rewritten to avoid Python code:
I had to do the same for all block_seq sequences, as well as for the mainsequence.
Finally, when testing your task through the browser, OSWeb will run a compatibility check and highlight certain problems.
For example, in OSWeb, the logger cannot be set to record all variables (this is because this would take a lot of resources and bandwidth in a browser), so the logger must be set manually. To test your task in a browser, I therefore had to disable the "Log all variables" option. You'll need to make sure to add manually all the variables you want to feature in the data log. Using the variable inspector can help greatly doing so.
I attach my modification of the task you posted in this forum:
The explanations above and the code should allow you to follow all the changes I made. I'm non holidays but decided to take a moment to go through this so that you can progress with your task, but please note that I did not test the whole task and that I'm not familiar with your design or objectives, so please complete and modify the task as required and make sure to check thoroughly your task and data output before using the task with real participants.
Hope this helps.
Kind regards,
Fabrice.
Hi Fabrice @Fab
Thanks so much for your detailed explanations and for taking the time to help! Very much appreciated.
The explanations are really helpful, and the changes needed were much more complicated than I thought. I have run your modified version in OSWeb and it works perfectly. I will process your explanations and complete and test the whole experiment.
Happy new year!
Best,
Mengzhu
Hi @Fab ,
Thanks very much again for your help. I have constructed the whole experiment and it worked in my browser fine. However, when my collaborator tried to run the experiment on the web, she got an error "compatibility check failed"... Do you have an idea about what might be going wrong?
Our counterbalance-Javascript (thanks again for helping convert and simplify the original python script to this Java one!) distributes participants into 8 different groups - the1st/9th participant would get List 1, and the 8th/16th participant gets List 8 etc.. As the OSWeb did not ask to enter the subject number (OS does), although we have specified the possible subject numbers to [0,1,2,3,4,5,6,7], we are not sure whether the first participant who clicked the link would be assigned to List 1, and the 9th participant would still be assigned to List 1?
Also, our experiment exceeds largely the recommended size, and I tried to deploy it once in Jatos TryOut Server, the loading time was indeed quite long. As our experiment collects reaction times data, would loading time (and logging too many variables) affect the recording/accuracy of participants' reaction times?
Thanks very much in advance!
Best regards,
Mengzhu
Hi @Yuyanxue,
I'm glad my help was of use and that your experiment is now almost running.
To answer your questions, the subject number will be randomly allocated by the program, which means that it is not possible to ensure that you get the same number of participants with id numbers 0 to 7. There currently is no easy solution to that problem. the issue is that the task runs on the participant's machine and not on a central server. This allows for proper temporal resolution and makes the task a lot more reliable, but the downside is that each individual instance of the task has no way of knowing hoe many participants have been tested with each id across all the different computers participants have used across various locations. If you have a set list of participants to invite to take part, one thing you can try, to try to get roughly similar numbers in each of the 8 conditions, is to modify the task to ask participants to enter an id number and instruct individual beforehand to use such or such number. However, in most cases this is not practical to do.
As for the size of the task, it should not affect the accuracy of RTs but it will affect the time it takes for the task to load up when it starts. Most people have a relatively fast connection speed, so that should not be an issue.
The time taken to log the data is fairly short but will vary depending on the number of variables you want to collect (for this reason, OSWeb requires the "log all variables" to be disabled). Unless you're logging tens of variables, this should not be an issue.
Hope this helps.
Kind regards,
Fabrice.
Dear @Fab
Thanks very much again for your detailed suggestions. As for the size of the experiment, I have changed all sound files from .wav to .mp3 tp reduce the size, but the experiment returned the following error right after a few sketchpads indicating experiment instructions and before the inline java script:
Uncaught TypeError: Cannot read properties of null (reading 'cloneNode')
See the console for further details
Does this mean that OSWeb does not support mp3 files?
Thanks in advance!
Best regards,
Mengzhu