Variable values in loop not synchronized
Hi folks,
I have a loop that contains a sequence. In the sequence there is an inline script that increments an experimental variable. (The variable was initialized to zero before the loop.) Immediately after the script I have a text form that displays the value of the variable. I can see that the variable value is correct by looking at it in the variable inspector and by printing its value out in the debug window. However, the value displayed in the text form is incorrect - it is the value the variable had before the latest increment, i.e., what it had on the last iteration of the loop. How can I fix this?
Here's a simplified, concrete example:
Before the loop I set the variable (total_points) to zero, e.g.,
var.total_points = 0
In the first iteration of the loop:
a. the inline-script increments the value by 10, e.g. var.total_points +=10
b. the variable inspector and the printout in the debug window both show that var.total_points is 10
c. the text form has the line "You have a total of [total_points] points" . The form displays
"You have a total of 0 points", which is incorrect
In the second iteration of the loop:
a. the inline-script increments the value by 10, e.g. var.total_points +=10
b. the variable inspector and the printout in the debug window both show that var.total_points is 20
c. the text form displays "You have a total of 10 points", which is incorrect. Note that the form is displaying the value of total_points from the previous iteration
In the third iteration of the loop:
a. the inline-script increments the value by 10, e.g. var.total_points +=10
b. the variable inspector and the printout in the debug window both show that var.total_points is 30
c. the text form displays "You have a total of 20 points", which is incorrect. Note that the form is displaying the value of total_points from the previous iteration
etc.
Any suggestions? (I have OpenSesame 3.2.8 running on Windows 10.)
Thanks.
Greg Reese
Comments
Hi Greg,
I am not sure how it works with forms, but what you describe sounds a lot like the typical issue of a prepare-run strategy mess up. Certain items are drawn during the prepare phase of a sequence, others during the run phase. The updating of the code seems to be in the run phase, whereas the form is being drawn in the prepare phase. Is that possible? If you put the code in the prepare phase does the problem still occur?
Eduard