# RSVP stream: varying target position?

**URL:** <https://discourse.psychopy.org/t/rsvp-stream-varying-target-position/8912>\
**Category:** Coding\
**Created:** [August 29, 2019, 9:39pm UTC](https://discourse.psychopy.org/t/rsvp-stream-varying-target-position/8912 "2019-08-29T21:39:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![psych](https://avatars.discourse-cdn.com/v4/letter/p/ec9cab/32.png) [@psych](https://discourse.psychopy.org/u/psych)\
**Post date:** [August 29, 2019, 9:39pm UTC](https://discourse.psychopy.org/t/rsvp-stream-varying-target-position/8912/1 "2019-08-29T21:39:09Z")

</div>

Hi, I’m looking to build an RSVP stream with a set length of 9 items. However, I want to vary the target location within the stream, so that it may be presented as either item 5, 6, 7, or 8 in each trial. I am looking to also counterbalance the target position. What would be the best way of doing this using the coder?

---

<div class="post-metadata">

**Author:** ![Michael](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/michael/32/16_2.png) [@Michael](https://discourse.psychopy.org/u/Michael)\
**Post date:** [August 29, 2019, 10:12pm UTC](https://discourse.psychopy.org/t/rsvp-stream-varying-target-position/8912/2 "2019-08-29T22:12:37Z")

</div>

Something like this code skeleton:

```auto
# assuming the number of trials is a multiple of 4,
# create a balanced list:
target_locations = [5, 6, 7, 8] * (number_of_trials/4)

# randomise its order:
numpy.random.shuffle(target_locations)

for trial_number, trial in enumerate(trials):
    this_target_location = target.locations.pop()

    for stimuli in range(9):
        if trial_number + 1 == this_target_location: # NB 0 vs 1 based
            # show the target
        else:
            # do whatever else

```

---

<div class="post-metadata">

**Author:** ![psych](https://avatars.discourse-cdn.com/v4/letter/p/ec9cab/32.png) [@psych](https://discourse.psychopy.org/u/psych)\
**Post date:** [August 30, 2019, 2:30am UTC](https://discourse.psychopy.org/t/rsvp-stream-varying-target-position/8912/3 "2019-08-30T02:30:51Z")

</div>

Thanks for this! Would you mind explaining how this works:

> [@Michael](#):
>
> ```auto
> for trial_number, trial in enumerate(trials):
> this_target_location = target.locations.pop()
> 
> for stimuli in range(9):
> if trial_number + 1 == this_target_location: # NB 0 vs 1 based
> # show the target
> else:
> # do whatever else
> 
> ```

---

<div class="post-metadata">

**Author:** ![Michael](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/michael/32/16_2.png) [@Michael](https://discourse.psychopy.org/u/Michael)\
**Post date:** [September 1, 2019, 4:34am UTC](https://discourse.psychopy.org/t/rsvp-stream-varying-target-position/8912/4 "2019-09-01T04:34:28Z")

</div>

> [@psych](#):
>
> Would you mind explaining how this works:

Can you be more specific? This is just an outline of the sort of structure your code would need, it won’t work by itself.

i.e. you need a loop for your trials (ideally a `TrialHandler` [psychopy.data - functions for storing/saving/analysing data — PsychoPy v2023.2.3](https://www.psychopy.org/api/data.html#trialhandler)), then within each trial, a loop for displaying the stimuli. But without seeing your own code, it is hard to be give more useful detail.
