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)