# Passing 1 or 2 more values in Dispatch and addlisten

**URL:** <https://forum.8thwall.com/t/passing-1-or-2-more-values-in-dispatch-and-addlisten/5108>\
**Category:** Technical Support\
**Created:** [March 5, 2025, 3:54pm UTC](https://forum.8thwall.com/t/passing-1-or-2-more-values-in-dispatch-and-addlisten/5108 "2025-03-05T15:54:48Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Peng\_Han\_Kum](https://avatars.discourse-cdn.com/v4/letter/p/977dab/32.png) [@Peng\_Han\_Kum](https://forum.8thwall.com/u/Peng_Han_Kum)\
**Post date:** [March 5, 2025, 3:54pm UTC](https://forum.8thwall.com/t/passing-1-or-2-more-values-in-dispatch-and-addlisten/5108/1 "2025-03-05T15:54:48Z")

</div>

What am I doing wrong?

I am trying to dispatch 2 variables, the ‘playerIndex’ and ‘selection’.  
===My dispatch code snippet===  
world.events.dispatch(world.events.globalId, ‘listens’, {  
playerIndex,  
selection,  
})

In another script, I cannot receive the ‘playerIndex’ and ‘selection’  
===My add listen code snippet===  
world.events.addListener(world.events.globalId, ‘listens’, (playerIndex, selection) =\> {

```
  if (schemaAttribute.get(eid).playerID === playerIndex) {
          console.log(selection)
    }

```

})

How do I addlisten for 2 variables?

---

<div class="post-metadata">

**Author:** ![GeorgeButler](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.8thwall.com/georgebutler/32/1903_2.png) [@GeorgeButler](https://forum.8thwall.com/u/GeorgeButler)\
**Post date:** [March 5, 2025, 4:55pm UTC](https://forum.8thwall.com/t/passing-1-or-2-more-values-in-dispatch-and-addlisten/5108/2 "2025-03-05T16:55:42Z")

</div>

The listener passes an object which has a “Data” property that contains your variables. Change your listener to something like this and check the console to see the entire event object:

```ts
world.events.addListener(world.events.globalId, ‘listens’, (e) => {
    console.log(e)
})

```

---

<div class="post-metadata">

**Author:** ![Peng\_Han\_Kum](https://avatars.discourse-cdn.com/v4/letter/p/977dab/32.png) [@Peng\_Han\_Kum](https://forum.8thwall.com/u/Peng_Han_Kum)\
**Post date:** [March 7, 2025, 3:13pm UTC](https://forum.8thwall.com/t/passing-1-or-2-more-values-in-dispatch-and-addlisten/5108/3 "2025-03-07T15:13:09Z")

</div>

This is the solution

world.events.dispatch(world.events.globalId, ‘playerSelectsModel’, {  
playerIndex,  
selection,  
})  
How to listen to more than 1 variable in addlisten  
// change body type when game starts  
world.events.addListener(world.events.globalId, ‘playerSelectsModel’, (e) =\> {  
console.log(‘Player Index:’, e.data.playerIndex)

---

<div class="post-metadata">

**Author:** ![GeorgeButler](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.8thwall.com/georgebutler/32/1903_2.png) [@GeorgeButler](https://forum.8thwall.com/u/GeorgeButler)\
**Post date:** [March 7, 2025, 6:13pm UTC](https://forum.8thwall.com/t/passing-1-or-2-more-values-in-dispatch-and-addlisten/5108/4 "2025-03-07T18:13:13Z")

</div>

If you wanted to use multiple variables you can do so like this

```auto
world.events.addListener(world.events.globalId, ‘playerSelectsModel’, (e) => {
    console.log(`Player Index: ${e.data.playerIndex}`)
    console.log(`Selection: ${e.data. selection}`)
})

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex019/uploads/x8thwall/original/2X/9/9212a857458f1b03a6accb129e0f8cbea408e3e5.png) [@system](https://forum.8thwall.com/u/system)\
**Post date:** [March 11, 2025, 6:13pm UTC](https://forum.8thwall.com/t/passing-1-or-2-more-values-in-dispatch-and-addlisten/5108/5 "2025-03-11T18:13:25Z")

</div>

This topic was automatically closed 4 days after the last reply. New replies are no longer allowed.
