juvahubeku Posted May 9, 2019 Share Posted May 9, 2019 Hello. I am developing a multiplayer game. I have a problem. I want the server to create a random number from 1 to 2. And send this number to all customers. But if clients play once, the server must regenerate the number I wrote such a function. She chooses a number from 1 to 2. And then always returns this number. If you restart the server, it will return a different number. project - https://fishscape.herokuapp.com/ var map_positions = [ { map: 1}, { map: 2}, ]; var vibrana_map = { map: 0}; function locateFood(data) { var roomId = data; var tmpName = room + roomId; if (vibrana_map.map == 0) { var map_num = Math.floor(Math.random() * 2); vibrana_map = map_positions[map_num]; io.in(tmpName).emit("foodPosition", vibrana_map); } else { io.in(tmpName).emit("foodPosition", vibrana_map); } } Link to comment Share on other sites More sharing options...
Recommended Posts