# Two quick questions

**URL:** <https://mworks.discourse.group/t/two-quick-questions/121>\
**Category:** Support\
**Created:** [May 27, 2021, 2:37pm UTC](https://mworks.discourse.group/t/two-quick-questions/121 "2021-05-27T14:37:33Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [May 27, 2021, 2:37pm UTC](https://mworks.discourse.group/t/two-quick-questions/121/1 "2021-05-27T14:37:33Z")

</div>

Hi Chris -

I’m continuing to adapt the example code you sent me (attached) and had a few questions:

(1) I dont see where in the protocol the parameter “num\_accepted” is updated  
(2) How do I adapt this code to show multiple repeats of the image set?

In looking over other example code provided with the install, I think you achieved point #2 above via the “when…” conditional in the final state of RSVPdemo.mwel :  
state ‘RSVP complete’ {  
report (‘\*\*\*\*\*\*\*\*\* RSVP Trial Completed \*\*\*\*\*\*\*\*\*’)  
sync = 0  
goto (  
target = ‘RSVP start’  
when = image\_set\_repeat\_count \< image\_set\_repetitions  
)  
yield ()

But I’m not sure how that "when…"would interfere with the current "when…"conditional in the final state of example1.mwel:

```
state 'End trial' {
        wait (inter_trial_interval)
        // If there are more images to show, start a new trial
        goto (
            target = 'Begin trial'
            when = num_accepted('image_index') < image_set_size
            )
        // Otherwise, exit the task
        yield ()

```

How do I correctly “loop” over two things? Image set size AND repetition set size?

Thank you!  
Yasmine

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [May 27, 2021, 3:23pm UTC](https://mworks.discourse.group/t/two-quick-questions/121/2 "2021-05-27T15:23:21Z")

</div>

Hi Yasmine,

> (1) I dont see where in the protocol the parameter “num\_accepted” is updated

num\_accepted is a [function](https://mworks.github.io/documentation/latest/expressions/index.html#functions), not a variable. If you pass it the _name_ of a [selection variable](https://mworks.github.io/documentation/latest/components/selection_variable.html) as a string ( `'image_index'` in your example experiment), it returns the number of accepted selections made on the variable. The current value of image\_index itself is controlled by the invocations of [reset\_selection](https://mworks.github.io/documentation/latest/components/reset_selections.html), [next\_selection](https://mworks.github.io/documentation/latest/components/next_selection.html), [accept\_selections](https://mworks.github.io/documentation/latest/components/accept_selections.html), and [reject\_selections](https://mworks.github.io/documentation/latest/components/reject_selections.html) throughout the protocol.

If you want more info on how MWorks’ selection mechanism works in general, there’s a [section on it](https://mworks.github.io/documentation/latest/guide/designing.html#selection) in the user manual.

> (2) How do I adapt this code to show multiple repeats of the image set?

Your reading of RSVPDemo is correct. To implement the same logic in example1, you need to add states at the beginning and end of the task to handle the image set repetition. I’ve attached an updated MWEL file that includes this change.

Cheers,  
Chris

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [May 27, 2021, 3:23pm UTC](https://mworks.discourse.group/t/two-quick-questions/121/3 "2021-05-27T15:23:21Z")

</div>

Attachment: [example1.mwel.zip](https://mworks.discourse.group/uploads/short-url/8otgueDpQojh4L0hO3jvNPZ9dY3.zip) (2.45 KB)

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [May 27, 2021, 5:19pm UTC](https://mworks.discourse.group/t/two-quick-questions/121/4 "2021-05-27T17:19:05Z")

</div>

Great - thanks Chris! Will work through all of this very shortly!  
Yasmine

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [June 8, 2021, 11:28pm UTC](https://mworks.discourse.group/t/two-quick-questions/121/5 "2021-06-08T23:28:41Z")

</div>

Hi Chris -

Since implementing the “image set repetitions” functionality in the  
example1.mwel, I’ve noticed two types of errors come up on the “Server  
Console” - although neither of them interfere with the progress of the  
experiment.

(1) ERROR: There are no more items left to draw [line 191: column 13]

In my code, this line is the beginning of the “Stim on” state. My  
understanding is that the code should only jump back to the “Stim on” state  
if there ARE stimuli left to draw at the end of a trial - so Im not quite  
sure why this is happening. Any ideas how to troubleshoot?

(2) An error warning that we skipped a screen refresh

Sorry I don’t have the exact wording - but wondering why this is happening  
and if we can do anything about it. It’s rare - but thought I’d point  
it out.

Thanks!  
Yasmine

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [June 9, 2021, 12:56pm UTC](https://mworks.discourse.group/t/two-quick-questions/121/6 "2021-06-09T12:56:31Z")

</div>

Hi Yasmine,

> (1) ERROR: There are no more items left to draw [line 191: column 13]

This happens when you invoke [next\_selection](https://mworks.github.io/documentation/latest/components/next_selection.html) after all selections have been exhausted. In the updated example I sent you, the state “End trial” checks whether all selections are exhausted and, if so, ends the current image set repetition:

```auto
// If there are more images to show, start a new trial
goto (
    target = 'Begin trial'
    when = num_accepted('image_index') < image_set_size
    )
// Otherwise, end the current image set repetition
goto ('End image set repetition')

```

On the other end, the state “Begin image set repetition” invokes [reset\_selection](https://mworks.github.io/documentation/latest/components/reset_selections.html) to reset the selection variable for the next image set repetition:

```
reset_selection (image_index)

```

If your code includes both those pieces and you’re still seeing the error, you can send me your MWEL, and I’ll try to spot the problem.

> (2) An error warning that we skipped a screen refresh

This means that, for some reason, MWorks wasn’t able to update the screen on a particular display refresh. Seeing this rarely isn’t cause for concern. There are many reasons why the system might experience an occasional performance “hiccup”, and I wouldn’t spend time trying to track down the (presumably transient) cause of these events.

However, if these warnings show up frequently, it means the graphics hardware is having trouble keeping up with MWorks’ needs. In that case, the problem might lie in MWorks. It also might be due to another application or process, or it could reflect an issue in the system’s graphics drivers. If you ever find yourself in this situation, let me know, and I can help you troubleshoot.

Cheers,  
Chris

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [June 21, 2021, 9:24pm UTC](https://mworks.discourse.group/t/two-quick-questions/121/7 "2021-06-21T21:24:10Z")

</div>

Hi Chris -

Following up on my email below about the error I’m getting in relation to  
calling next\_selection when there are no more stimuli to draw:

ERROR: There are no more items left to draw [line 191: column 13]

Any chance you spotted the error in my code?

Thank you!  
Yasmine

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [June 22, 2021, 12:13pm UTC](https://mworks.discourse.group/t/two-quick-questions/121/8 "2021-06-22T12:13:15Z")

</div>

Hi Yasmine,

> Any chance you spotted the error in my code?

Sorry, I never received your code. Can you try sending it again?

FYI, attachments with the extension “.mwel” sometimes cause emails to be treated as spam and lost. To avoid this, I recommend either adding a “.txt” extension to or ZIP compressing MWEL files before attaching them to an email. Sorry for the hassle!

Thanks,  
Chris

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [June 22, 2021, 1:01pm UTC](https://mworks.discourse.group/t/two-quick-questions/121/9 "2021-06-22T13:01:25Z")

</div>

Ah! Good to know. Re-attaching here as .txt.

Please let me know if you can access this.

Thanks!  
Yasmine

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [June 22, 2021, 1:01pm UTC](https://mworks.discourse.group/t/two-quick-questions/121/10 "2021-06-22T13:01:25Z")

</div>

Attachment: [example1\_YES.txt](https://mworks.discourse.group/uploads/short-url/padiquJ7dTvTYflRbeBOsJQeKv.txt) (19.2 KB)

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [June 22, 2021, 3:14pm UTC](https://mworks.discourse.group/t/two-quick-questions/121/11 "2021-06-22T15:14:06Z")

</div>

Hi Yasmine,

Thanks, I received it this time. There is an issue, but I think it’s in my original version, too. I’ll let you know once I’ve sorted it out.

Chris

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [June 28, 2021, 9:46pm UTC](https://mworks.discourse.group/t/two-quick-questions/121/12 "2021-06-28T21:46:03Z")

</div>

Hi Yasmine,

My apologies. The “no more items left to draw” message was due to an error on my part in the original example experiment. To resolve the issue, you need to make two changes.

First, in the definition of `image_index`, add the parameter [advance\_on\_accept](https://mworks.github.io/documentation/latest/components/selection_variable.html#advance-on-accept) with value `YES`:

```auto
selection image_index (
    values = 0 : image_set_size - 1
    selection = random_without_replacement
    advance_on_accept = YES // This is the line to add
    )

```

Second, in the state “Stim on”, replace

```auto
next_selection (image_index)

```

with

```auto
if (images_shown > 0) {
    next_selection (image_index)
}

```

I’ve attached a copy of your experiment file that includes these changes. With this version, you should no longer see the error message.

As for why these changes are necessary: [Selection variables](https://mworks.github.io/documentation/latest/components/selection_variable.html) are confusing (even to me), because sometimes they advance automatically to the next selection, and sometimes they don’t. Specifically:

- [reset\_selections](https://mworks.github.io/documentation/latest/components/reset_selections.html) does not automatically make a next selection. Immediately after being reset, a selection variable is in the “no selection” state. To make an initial selection, you have to either (1) invoke [next\_selection](https://mworks.github.io/documentation/latest/components/next_selection.html) explicitly or (2) just use the variable, as asking for the value of a selection variable in the “no selection” state causes a selection to be made automatically for you. Personally, while I think (1) is totally reasonable and expected, (2) is not so expected and a little unnerving. However, it doesn’t really matter in practice, because in both cases, you end up making one, initial selection.

- By default, [accept\_selections](https://mworks.github.io/documentation/latest/components/accept_selections.html) also does not make a next selection. However, unlike reset\_selections, accept\_selections doesn’t cause the selection variable to enter the “no selection” state. Rather, it leaves the current, just-accepted selection in place. You can alter this behavior by setting [advance\_on\_accept](https://mworks.github.io/documentation/latest/components/selection_variable.html#advance-on-accept) to `YES`, in which case accept\_selections _does_ make a next selection.

- Finally, [reject\_selections](https://mworks.github.io/documentation/latest/components/reject_selections.html) _always_ makes a next selection.

When writing the example for you, I forgot that reject\_selections makes a next selection. This meant that, when a trial failed before the current image set repetition was complete, the selection variable was advanced twice when it should have been advanced only once: implicitly by reject\_selections, and explicitly by the next\_selection invocation in state “Stim on”. This resulted in the first of those two selections (i.e. images) never being used, and it caused the next trial to “consume” more than `images_per_trial` images, which in turn led to later trials running out, hence the “no more items left to draw” error. The changes I outlined above fix the problem by

1. making _both_ accept\_selections and reject\_selections automatically make a next selection and
2. explicitly invoking next\_selection only when _not_ at the beginning of a trial.

If you think this all sounds ridiculous and highly conducive to errors, I agree! I didn’t implement selection variables, and if I could re-make them from scratch, they would _never_ implicitly make a next selection. However, I can’t change their behavior now, because doing so would break the many, many experiments that are designed around and depend on the existing behavior. I suppose I could make a new, alternative selection variable that behaves in ways that I find sensible, but that might just muddy the waters further.

If you have any suggestions for how to improve this situation, please let me know! In the meantime, the changes I described should make the selection-variable bits of your experiment work correctly.

Cheers,  
Chris

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [June 29, 2021, 12:14pm UTC](https://mworks.discourse.group/t/two-quick-questions/121/13 "2021-06-29T12:14:37Z")

</div>

> I’ve attached a copy of your experiment file that includes these changes.

For some reason, the attachment failed to upload. Trying again.

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [June 29, 2021, 12:14pm UTC](https://mworks.discourse.group/t/two-quick-questions/121/14 "2021-06-29T12:14:37Z")

</div>

Attachment: [example1\_FIXED.txt](https://mworks.discourse.group/uploads/short-url/p4pCL24k83FEefntT8ZHZChHkNf.txt) (19.2 KB)

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [June 29, 2021, 12:21pm UTC](https://mworks.discourse.group/t/two-quick-questions/121/15 "2021-06-29T12:21:01Z")

</div>

> if I could re-make them from scratch, they would never implicitly make a next selection. However, I can’t change their behavior now, because doing so would break the many, many experiments that are designed around and depend on the existing behavior.

Now that I’ve vented my frustrations, it occurs to me that I could just add a new parameter that enables alternative, more predictable behaviors for selection variables. That would avoid breaking existing experiments, while allowing new ones to opt in to the new behaviors. That’s probably what I’ll do.

Chris

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [July 1, 2021, 12:53am UTC](https://mworks.discourse.group/t/two-quick-questions/121/16 "2021-07-01T00:53:15Z")

</div>

Hi Chris.,

Super - I received your detailed commentary on that next selection error  
and will work through it today! And sounds good about a new parameter for  
getting more predictable behaviors for selection variables!

Thank you,  
Yasmine

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [July 1, 2021, 12:59am UTC](https://mworks.discourse.group/t/two-quick-questions/121/17 "2021-07-01T00:59:11Z")

</div>

Hi Chris -

I made the two changes you suggested:

_CHANGE 1_  
selection image\_index (  
values = 0 : image\_set\_size - 1  
selection = random\_without\_replacement  
advance\_on\_accept = YES //Y: Added this line to  
get rid of “ERROR: no more items left to draw”  
)  
_CHANGE 2_  
state ‘Stim on’ {  
if (images\_shown \> 0){ //Y: Added this line to  
get rid of “ERROR: no more items left to draw”  
next\_selection (image\_index)  
}

Last night, I ran the code with mouse simulation in eyelink, without moving  
the mouse – and didn’t see the error come up. But today, we ran an animal  
and we did get the error. I suspected that this was due to breaking  
fixation and the state called “Trial failure” which also contains a  
“reject\_selections (image\_index)”. To confirm, I re-ran eyelink with mouse  
simulation and then introduced some simulated broken fixations…and sure  
enough, I got the error again.

I do think the error is less frequent than it was previously…but Im  
wondering if we should edit the “Trial failure” state?

Thanks!  
Yasmine

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [July 2, 2021, 12:37pm UTC](https://mworks.discourse.group/t/two-quick-questions/121/18 "2021-07-02T12:37:04Z")

</div>

Hi Yasmine,

Yes, it was reject\_selections in the “Trial failure” state that triggered the error. I thought my changes had fixed that, but it sounds like they haven’t.

Can you send me the exact experiment file you’re having problems with? Maybe there’s another issue I missed.

Thanks,  
Chris

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [July 2, 2021, 8:26pm UTC](https://mworks.discourse.group/t/two-quick-questions/121/19 "2021-07-02T20:26:03Z")

</div>

Hi Chris -

Attaching the most recent version of our code (and %include files) in a  
compressed folder.

Thank you,  
Yasmine

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [July 2, 2021, 8:26pm UTC](https://mworks.discourse.group/t/two-quick-questions/121/20 "2021-07-02T20:26:03Z")

</div>

Attachment: [YESCODE-forStawarz.zip](https://mworks.discourse.group/uploads/short-url/r2P0jOCQsGl6QxLnnygg1lZLa70.zip) (9.99 KB)

[Next page](https://mworks.discourse.group/t/two-quick-questions/121.md?page=2)
