Sign in to follow this  

Generate number on server and send all clients

Recommended Posts

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 -

var map_positions = [
  { map: 1},
  { map: 2},
var vibrana_map = { map: 0};
function locateFood(data) {
  var roomId = data;
  var tmpName = room + roomId;
  if ( == 0) {
    var map_num = Math.floor(Math.random() * 2);
    vibrana_map = map_positions[map_num];"foodPosition", vibrana_map);
  else {"foodPosition", vibrana_map);

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.