# Intermittent Reward

**URL:** <https://mworks.discourse.group/t/intermittent-reward/328>\
**Category:** Support\
**Created:** [June 18, 2018, 9:07pm UTC](https://mworks.discourse.group/t/intermittent-reward/328 "2018-06-18T21:07:08Z")\
**Posts on this page:** 5\
**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:** [June 18, 2018, 9:07pm UTC](https://mworks.discourse.group/t/intermittent-reward/328/1 "2018-06-18T21:07:08Z")

</div>

Hi Chris,

Is there an easy way to give rewards at a defined interval within a trial? For instance, if I have a monkey fixating and the trial can run for a maximum of 20s, how can I make it so the monkey gets rewarded every 2s that he fixates? I have a command to send reward through our system, but all the reward conditions in the codes I have are separate states, and I’m not sure how to integrate this type of reward using states like that.

I was thinking of using a timer within the fixation state that when it expires, the monkey gets rewarded and the timer starts over, but I’m totally unsure how to actually write something like that so that it works.

Thanks!  
Yvonne

---

<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 19, 2018, 8:14pm UTC](https://mworks.discourse.group/t/intermittent-reward/328/2 "2018-06-19T20:14:51Z")

</div>

Hi Yvonne,

> I was thinking of using a timer within the fixation state that when it expires, the monkey gets rewarded and the timer starts over

That could work, although it gets complicated when fixation spans multiple states (as it often does).

It might be simpler to use [scheduled actions](https://mworks.github.io/documentation/latest/components/schedule_actions.html). I’ve attached an example demonstrating one way to do this. Key points to note:

- `end_reward` must be false before the scheduled actions begin.
- The “Fixation started” state does not need to transition directly to “Fixation ended”. There can be any number of intermediate states.
- Be sure that `end_reward` is always set to true somewhere in your task. Otherwise, the periodic reward will continue indefinitely.

If you have any questions, please let me know.

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 19, 2018, 8:14pm UTC](https://mworks.discourse.group/t/intermittent-reward/328/3 "2018-06-19T20:14:51Z")

</div>

Attachment: [periodic\_reward.mwel.zip](https://mworks.discourse.group/uploads/short-url/wXhmeMBP1vn3Hy7HNKWrbG1IEzD.zip) (779 Bytes)

---

<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, 2018, 8:55pm UTC](https://mworks.discourse.group/t/intermittent-reward/328/4 "2018-06-21T20:55:30Z")

</div>

Hi Chris,

This worked great, thanks so much!

Best,  
Yvonne

---

<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 19, 2022, 9:44pm UTC](https://mworks.discourse.group/t/intermittent-reward/328/5 "2022-07-19T21:44:51Z")

</div>

Closed on July 19, 2022, 9:44pm UTC


