data not saving correctly with jatos.startComponentByPos()

55 views
Skip to first unread message

Becky Gilbert

unread,
Apr 5, 2018, 1:07:55 PM4/5/18
to JATOS
Hi JATOS group,

I'm having a strange problem with the jatos.startComponentByPos() function. During the experiment, one of 16 task versions is selected randomly, and the experiment jumps to the component that corresponds to the version that was selected. Then, at the end of all 16 versions, the person always jumps to the last component.

So, in the component at the beginning (before the jump to a specific version), a variable called 'component_position' is created with the component number for the selected version. At the end of this component, the data is saved and the person moves on to the component number that corresponds to the selected version:

jatos.submitResultData(resultJson, jatos.startComponentByPos(component_position));

Then, at the end of the 16 different task versions/components, the data is saved and the experiment jumps to the last component, which is 22:

jatos.submitResultData(resultJson, jatos.startComponentByPos(22));

The components are always presented as they should be. However, the data is not saving correctly. In the example below, the data was not saved for the randomly-selected version/component, despite the fact that the component finished successfully and the experiment moved on to the next component.


And sometimes the data is saved to the wrong component. Below is an example where the data from the component before the first jump to the randomly-selected version/component was saved to the next component (the randomly selected one): 



I would normally assume that I've done something wrong in the code, however the very strange thing is that the data saves correctly on my local JATOS. TSo far this problem has only happened when doing the task with the JATOS running on our server, and this problem has occurred every time we've tested it on the server. Here is an example of the data saving correctly in my local JATOS:



So I'm very confused about what is going on here. Any ideas?!


Thanks,

Becky



Kristian Lange

unread,
Apr 5, 2018, 2:58:45 PM4/5/18
to Becky Gilbert, JATOS
Hi Becky,

that sounds indeed strange and I have no answer out of the box. Your jatos.js calls look all fine. My first guess is that JATOS might display data wrongly in its GUI. Could you please tell me what the JATOS version is on your server and which one you use locally?

Best,
Kristian

--
You received this message because you are subscribed to the Google Groups "JATOS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jatos+un...@googlegroups.com.
To post to this group, send email to ja...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jatos/0b7c19d8-25a4-4caa-bb13-2f6a4ae9c339%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Becky Gilbert

unread,
Apr 20, 2018, 10:45:59 AM4/20/18
to JATOS
Dear JATOS users,

Kristian found the solution to this problem. The issue was that the jatos.submitResultData function needs a reference to a function for the 'on success' argument, e.g.

jatos.startNextComponent

but I was passing it the function call itself (with parentheses at the end of the function name), e.g.

jatos.startComponentByPos(component_position)

So this 'on success' function was being called before the result data was submitted. The solution is wrap everything in an anonymous function. Kristian's explanation is below. Thanks very much Kristian!

I'm pretty sure I found the problem. It's an JavaScript thing. Actually I could have seen it in your first email but it's quite subtle so I missed it too.

This line is okay
jatos.submitResultData(resultJson, jatos.startNextComponent);
the jatos.submitResultData gets two parameters and the second one is actually a reference to a callback function.

Now this your student's line
jatos.submitResultData(resultJson, jatos.startComponentByPos(component_position));
Here the second parameter is actually not a reference to a callback function - it's the function call itself. So JavaScript first calls jatos.startComponentByPos(component_position) and then uses the return value of this function call as a second parameter for the jatos.submitResultData call. Since jatos.startComponentByPos doesn't return any value JavaScript probably uses null or something similar. The order is: 1) jatos.startComponentByPos, and 2) jatos.submitResultData - like in the log.
 
And this is how it should look:
jatos.submitResultData(resultJson, function () {
jatos.startComponentByPos(component_position);
});
Here you pass on a function as the second parameter. 

Please try this in your study. I'm pretty sure it will work now. 

I will add an additional example with jatos.submitResultData and jatos.startComponentByPos in the jatos.js reference.
Reply all
Reply to author
Forward
0 new messages