open-cogsci / OpenSesame

Graphical experiment builder for the social sciences
http://osdoc.cogsci.nl/
GNU General Public License v3.0
236 stars 112 forks source link

Sketchpad on loop variable "duration" not set at first iteration #772

Closed rChahine closed 2 years ago

rChahine commented 2 years ago

Hi

# system information
API: 2.1
OpenSesame: 3.3.9b1
Platform: posix

I'm trying to run a loop that contains a keyboard which updates a global variable named "Ta".

"Ta" has been initialized at 0 before the loop. githubissue

At the first iteration, "Ta" has no effect on the duration of Sketchpad "Blanck_part3_2", then, since the second iteration, the correct duration is set.

We know that the duration of "Blanck_part3_2" at the first iteration is the initial value despite the incrementation of "Ta"

Here's the code for handling keyboard input and update "Ta" variable:

my_keyboard = Keyboard(keylist=['S', 'L', 's', 's'], timeout=500)

start_time = clock.time()
_, end_time = my_keyboard.get_key()

var.Ta += end_time - start_time  # end_tme - start_time = temps d'execution
print(f"itération no: {var.count_2} | Ta -> {var.Ta}")

Here the output (that works as expected)

itération no: 0 | Ta -> 234.66181755065918  # Blanck_part3_2 duration is not set
itération no: 1 | Ta -> 298.0988025665283  # Blanck_part3_2 duration is set correctly
itération no: 2 | Ta -> 319.02170181274414 # Blanck_part3_2 duration is set correctly
itération no: 3 | Ta -> 331.1147689819336 # Blanck_part3_2 duration is set correctly

Here's how we set duration to "Blanck_part3_2" sketchpad python set duration "[Ta]"

Do you have any idea what's wrong ?

thanks

smathot commented 2 years ago

I suspect that this happens because the Blanck_part3_2 prepared before the Ta variable is set, as explained in this section of the documentation:

If that's not it, would you remind reposting this question on the support forum? I'm closing the issue here because it's not an issue as such, but rather a question related to usage.