andre
Experienced
Posts: 35
|
Post by andre on Jul 29, 2020 6:27:36 GMT
I have the following structure: 1. A 'Survey' which asks some details of the participant, e.g. their gender, age and a short questionnaire for which a sum of the scores is calculated. 2. Then this Survey calls an Experiment ("l: experiment")
Is it possible to pass variables from the Survey to the experiment? For example that I could use the gender, age, and calculated variable from the Survey to, for example (it's all a bit hypothetical) that I could adjust duration of stimulus duration based on age, and save these variables also in the Experiment result file.
Kind Regards,
Andre
|
|
|
Post by PsyToolkit on Jul 29, 2020 15:47:12 GMT
Yes absolutely, that is one of the great advantages of PsyToolkit. It is very straightforward. Here is the detailed documentation about how to do this: www.psytoolkit.org/lessons/var_in_out.html
If anything is still unclear, please ask.
|
|
andre
Experienced
Posts: 35
|
Post by andre on Jul 29, 2020 16:48:43 GMT
Thanks a lot, this seems to be exactly what I was looking for. Just to clarify, I presume I can also var in a calculated variable, e.g. (from one of the template scales): l: neuroticism t: set - mean $bfi.1 $bfi.2 $bfi.3
Then I could use in the Experiment: var in neuroticism and access it with &neuroticism
Hmm, I just realised, 'neuroticism' wouldn't be integer. Is there a way to convert that?
|
|
|
Post by PsyToolkit on Jul 30, 2020 17:38:16 GMT
You can solve it this way:
For example do the question you have.
l: neuroticism t: set - mean $bfi.1 $bfi.2 $bfi.3
It would round the value, you can also do this:
l: neuroticism t: set - calc ( $bfi.1 $bfi.2 $bfi.3 ) / 3 * 1000
Then in experiment script
options var in neuroticism
task my_task if &neuroticism > 2000 show text "the neuroticism score is higher than 2"
fi
In other words, you get around it by multiplying. Thus in the example, if the person's neuroticism score is, say, 2.5, then it will actually be 2500 in the coding.
Let me know if that is clear/unclear.
|
|
andre
Experienced
Posts: 35
|
Post by andre on Jul 31, 2020 8:28:06 GMT
Thanks, that helps.
Just out of curiosity (no need to answer if you're busy): Does this work because the 'mean' function automatically truncates decimal places (max 2 or 3 places) or because when you do 'var in neuroticism' it doesn't care whether there are decimal places or not, it just ignores them?
I was probably thinking too complicated in the sense that a variable 'neuroticism' is either of type 'int' or 'double' and, if the latter, couldn't be used for 'var in' even if it would be a whole number.
|
|
|
Post by PsyToolkit on Aug 2, 2020 9:21:43 GMT
That is a good point.
I need to improve the code somewhat in this respect.
I agree that having "doubles" would be useful.
Currently, you can actually use the "double" in the PsyToolkit script, but it seems to round it to an integer as soon as you use them for new calculations.
|
|
andre
Experienced
Posts: 35
|
Post by andre on Aug 6, 2020 19:54:30 GMT
Sorry, but I can't get it to work. I used the following code, based on your suggestions above: In Survey: l: Age t: textline q: How old are you? - {min=18,max=100,require} Your age in years:
Question: In the Survey, do I need to specify also the bit where it says "If you want to get information from calling link to the survey (in), or want to send information using the end URL (out)..." and the fields In: and Out:? I haven't specified anything here, because this seems to relate to something else.
In the experiment code, when I just add: options var in age
and later on save [...] &age
I get an error message for the save command, that the global variable "&age" is not known.
Therefore, I changed the Options: options set &Age -999 var in &Age (I've also tried var in Age, i.e. without "&")
And later in the trial save [...] &Age
Then the -999 is saved in the output file, but not the value entered in the Survey.
I'm sure I'm missing something?
|
|
|
Post by PsyToolkit on Aug 8, 2020 17:01:46 GMT
This might be a bug in the code.
What you can do is this in your experiment
options
var in age
task sometask set &new_age &age save &new_age
Please let me know if that works.
|
|
andre
Experienced
Posts: 35
|
Post by andre on Aug 11, 2020 8:35:14 GMT
Unfortunately, it doesn't
In your example, the line in the task definition: set &new_age &age
gives an error message: ERROR: undefined_global_variable in line: 89 >>> set &nage &age Problem: You use a global variable that has never been set. The name of this variable in your script is called &age
It looks like the "var in age" command does not create/define a new variable 'age' That's the reason why I tried defining the variable before this: options set &age -999 var in age [or] var in &age However, then &age just stays -999
|
|
andre
Experienced
Posts: 35
|
Post by andre on Aug 11, 2020 8:45:12 GMT
Just to point out again, I haven't specified anything here (in the Survey): If you want to get information from calling link to the survey (in), or want to send information using the end URL (out), provide variables here. You typically will only have one for in and out, but if you have more than one, separate with a space. In: Out:
If I need to specify the variables there as well, let me know. But they seem to refer to the real external communication with other websites.
|
|
laram
New Member
Posts: 3
|
Post by laram on Mar 29, 2021 15:32:47 GMT
I have exactly the same problem here as andre - did you ever resolve it? The var in option in the experiment does not create a global variable to use in the experiment as expected, and leads to "ERROR: undefined_global_variable" issues. The variable definitely exists in the survey, in which the experiment is embedded. I would be very grateful for any solution.
|
|