|
Post by juochoa on Jan 6, 2021 17:35:32 GMT
The code I have written seems to be working exactly how I want it, however, the experiment will freeze at random points. I believe it has something to do with the "if $a == $r" condition not working properly. The code will run fine then after some time of it working, it will simply stop. After several days of troubleshooting, I have not been able to pinpoint what might be causing it. If anyone has an idea of what might be causing the code to freeze, please let me know! The code for the experiment can be found below:
options fullscreen mouse on escape
bitmaps SD Sdelta Neutral Reinforcement Instructions Thankyou
task baseline_left mouse on set $clicksSD 0 set $clicksSdelta 0 set $cubecounter 0 set $a 0 timestamp start while $cubecounter < 10 set $r random 5 11 draw off show bitmap SD -225 0 show bitmap Sdelta 225 0 draw on readmouse l 1 100 range 1 2 if STATUS == 1 set $clicksSD increase 1 set $a increase 1 fi if STATUS == 2 set $clicksSdelta increase 1 fi if $a == $r mouse off show bitmap Reinforcement set $a 0 set $cubecounter increase 1 delay 1000 clear -1 mouse on fi while-end timestamp stop set $time timestamp-diff start stop save BLOCKNAME $time $clicksSD $clicksSdelta $cubecounter
block baseline message Instructions tasklist baseline_left 2 end
|
|
silk
Experienced
Posts: 32
|
Post by silk on Jan 9, 2021 16:16:24 GMT
Hi there, I think I found where is the problem in your script. In fact, your experiment doesn't freeze, it just runs indefinitly because of your $a variable. You were right when you said that the if $a == $r condition is responsible of the "freeze". In your experiment : - You assign a random number between 5 and 11 to your $r.
- Sometimes you increase your $a variable, and if this variable is equal to $r you reset $a to 0.
So you expect that, at some point in your script, $a will be equal to $r. However there is a situation where it never happens : when $a is increased over 11, which is the "upper-limit" of the $r variable. Since the value assigned to $r is random, there is a possibility that $a is never equal to $r for the 11 first times you increase $a. If so, $a will be increased over the upper-limit of $r and you will be stuck in a loop where $a can never be equal to $r.
One way to correct this is to add a condition to make sure that the script won't continue if $a is superior to 11. However the place where you want to put this condition depends a lot of what you want to do with your experiment. My fix would be to say something like "if $a is equal to $r, or if $a is superior to 11, then blablabla", which could be scripted as : if $a == $r || $a > $r
|
|
|
Post by juochoa on Jan 12, 2021 19:07:56 GMT
This fixed it!! Thank you so so so much for your help! I will remember to add in a safeguard for limits like this in the future.
Thank you again!!
|
|