The variable 'target' does not exist.
Hello, this might be a quiet simple question, but I have trouble causing the experiment to stop.
I am making self-paced reading experiment with this inline script(the 'sentence' source is in table :
sentence_decomposition=var.sentence.split(" ") var.word_count=len(sentence_decomposition) var.target_words_list=sentence_decomposition[::-1]
This part is running smoothly.
I added a new loop to display the target, and repeat it for [word_count]
define loop new_loop set source_file "" set source table set repeat "[word_count]" set order random set cycles 1 set continuous no set break_if_on_first yes set break_if never setcycle 0 empty_column "" run new_sequence
inside the loop, I added new sequence with another inline script to show words.
this is the code of inline script 'get_sentence'
define inline_script get_sentence set description "Executes Python code" set _run "var.target=target_words_list.pop()" set _prepare ""
and it seems like this part is causing the issue. I've designated the target and added sketchpad in the same sequence to print the target. but it says the variable target does not exist.
--
The variable 'target' does not exist. Tip: Use the variable inspector (Ctrl+I) to see all variables.
details:
item-stack: experiment[run].practice_loop[run].block_sequence[run].block_loop[run].trial_sequence[run].new_loop[run].new_sequence[prepare].t1[prepare]
--
I viewed the variable inspector and saw target value was empty, but target_words_list had proper value.
Since I am a beginner with OpenSesame, cannot find out what is problem with my code.
Comments
Hi @fredcowh,
Can you share your experiment? With solely the snippets that you shared, I cannot tell what is happening here.
Thanks,
Eduard
Hello @eduard , Thank you for your comment.
I will share the file here.
Hi,
I recommend you check out the information on prepare/run in the documentation:https://osdoc.cogsci.nl/4.0/manual/prepare-run/
In your case, you need to put your code in the
get_sentence
inline_script in the prepare phase and not in the run phase. Similarly, I would do the same for the inline_scriptanalyze_sentence
.Hope this clears things up.
Eduard
Hi, @eduard
Thank you for your help. I just moved both codes to prepare phase.
But I still have an issue with Name error.
NameError: name 'target_words_list' is not defined
I checked all the name and there was no mistake.
Still 'target_words_list' has the value (the reversed word), and it is global, variable 'target' couldn't get the value.
I have no idea why this happens.
You called this variable
var.target_words_list
nottarget_words_list
You need to be consistent. If I add thevar.
it works for me.Eduard
Hi,
I checked the variable name, and it worked! That was a silly question...
Your answer helped me a lot.
Thank you so much!