#Getting a GM or GM Proxying

1 messages · Page 1 of 1 (latest)

bitter sphinx
#

so it does seem like the order is guaranteed, I'm guessing based on insertion order. But I'm curious if there is a chance for skew.

slender tide
#

I recently ask whether there is a guaranteed order of documents in a collection. The answer was no, so I assume it's the case here as well.

#

Sorting the users by user id and then selecting the first GM is probably safer

civic bramble
#

The id is randomly generated tho, so that seems pointless.

But yeah, there's no guarantees on the order of users.

coral mesa
#

Sorting by ID would be guaranteed to be the same order across multiple clients, at least

lofty shard
#

I would suggest filtering and then sorting, rather than sorting and then filtering, but it’s small data so not a big deal

bitter sphinx
#

thanks all

#

in case someone looks at this archive in the future I guess it would be something like:
game.users.filter(u => u.isGM && u.active).sort((a, b) => a.id.localeCompare(b.id)).shift()

ionic fog
bitter sphinx
civic bramble
#

Setting second parameter of localeCompare to something specific would get more predictable results.

civic bramble
bitter sphinx
civic bramble
#

I believe it is.

ionic fog
civic bramble
left mural
#

This is how I ensure only one GM acts, but it sounds like this may be flawed if the list isn't guaranteed to be the same.

let GMs = game.users.filter(user => user.isGM && user.active);
                
            if (GMs[0].id != game.user.id){
                    return;
            }```
ionic fog
left mural
#

I guess if I throw a sort in as was being discussed, that would guarantee it

#

Although I'd expect the list of GMs to be consistent by order of login time anyway

ionic fog
#

The login time has nothing to do with that, as far as I understand.