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)
}
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:
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)