Hello and welcome to the forum,
To send data to the server, quite simply:
player.emit("players-info", { allPlayers })
To retrieve it in a GUI
<template>
<div></div>
</template>
<script>
export default {
name: 'player-controller',
inject: ['rpgSocket'],
mounted() {
this.rpgSocket().on('players-info', (data) => {
console.log(data);
});
}
}
</script>
Full example:
Server Side:
const controllerGUI = player.gui("player-controller");
controllerGUI.on("players-info", (data) => {
console.log("okay", data);
if (data.players) {
}
});
controllerGUI.open();
player.emit("players-info", { allPlayers }); // Be careful, as it's asynchronous: you have to wait for the component (GUI) to be displayed before sending data. Here, we're doing the 2 in parallel, so there may be a bug.
GUI:
<template>
<div></div>
</template>
<script>
export default {
name: 'player-controller',
inject: ['rpgSocket', 'rpgGuiInteraction'],
mounted() {
this.rpgSocket().on('players-info', (data) => {
console.log(data);
this.rpgGuiInteraction('player-controller', 'players-info', data) // to send
})
}
}
</script>