Reset variable for adaptive procedure
I'm still quite new to Python (and programming in general) and trying to code a working-memory task (word span sequences) with an adaptive number of items to be remembered, depending on the performance in the trial before; however it is only adapted every two trials. In total there are 10 trials. I have a set of 9 words, from which randomly a number "n" is drawn.
So let's say I start with 3 words in a sequence and get two trials right, the number of words for the next two trials should increase to 4. If I get these next two wrong, the number should reduce to 3 again. If I get one correct and one wrong, the number of words per sequence should remain the same.
The words are to be presented one by one acoustically (with a ISI of 1500ms), and at the end the whole sequence is presented to the person administering the test. That person scores with "1" or "0" whether the response was correct or not (i.e. whether the sequence was reproduced correctly)
So I created a loop that contains 10 trials in sequential order and a "reset" variable that is alternatingly "0" and "1". The loop calls a sequence that contains two inline scripts. The first is for resetting my "adapt"-variable to 0, the second contains the actual trial.
So far so good, but the adaptive procedure "every other trial" does not seem be stable, Python produces quite frequent crashes, mostly after 5-7 trials. Most of the time the window just freezes and has to be shut down manually.
I assume that my coding is erroneous or contains pitfalls that I naively don't see
I begin with evaluating whether the "adapt"-variable is +2 or -2 (from the previous two trials) and accordingly adjusting "n" (passed to function random.sample)
if adapt == -2: var.n = var.n - 1 elif adapt == 2: var.n = var.n + 1
After the presentation of the sequence, I collect the keyboard response (0 or 1), adjusting "adapt" accordingly
if var.correct == 1: adapt = adapt + 1 else: adapt = adapt - 1
After every other trial, the "adapt" variable should be reset to zero, so that it only reflects two trials. I had to insert an extra inline script because within the actual trial-script it would not work at all. This way works sometimes, however not very stable. It seems to work when I omit the "adapt" procedure every two items and change the number of words per sequence after every trial:
if var.correct == 0: var.n = var.n - 1 elif var.correct == 1: var.n = var.n + 1
I also get a
UserWarning: var name is stored as attribute of item experiment % (var, self.item.name))
which I found in another post (http://forum.cogsci.nl/index.php?p=/discussion/2616/random-crashes-on-droid-back-end-possibly-connected-to-var-store-warning), but appearantly it is not related to the issue? (although however, the phenomenon seems quite similar). In the other post it was suggested that memory may be an issue, however I'm running OS on a regular windows Laptop and am not using large files.
So do you have any ideas how I could solve this; maybe a completely different and more reasonable approach?
It will be very much appreciated