[SOLVED]How do I make a list of everyone that is in a room?

2 favourites
  • 7 posts
From the Asset Store
Add calm and a lounge vibe to your games with these 8 tracks
  • Simple Chatroom.

    Whats supposed to happen

    • text object that lists every PeerAlias and their PeerID in the room (including the host)
    • as soon as someone joins/leaves the room, update that list

    What actually happens

    • nothing happens

    I tried to use an Array, but they don't support strings, so I tried with a Dictionary

    every tick it would set the Key and the Value for that key to this:

    Key: multiplayer.peerAliasAt(loopindex)

    Value: multiplayer.peerIDat(loopindex)

    but since Dictionaries don't support numbers I have to do it like this

    Key: multiplayer.peerAliasAt(multiplayer.peerCount)

    Value: multiplayer.peerIDat(multiplayer.peerCount)

    In theory, every time a new peer joins it should just get the Alias and ID of the newest peer.

    I don't know if its really obvious and it just something that I missed. Can somebody help.

  • does nobody know?

    Nepeo

    maybe you can help

  • While the Dictionary ACEs don't support numbers for the key you can convert your number into it's string form to use as a key. The key is unique and reproducible still so that should work fine for your use case.

    The str(mynumber) expression will convert a number to a string. int(mynumericalstring) and float(mynumericalstring) will convert a numerical string into a integer or float respectively for the reverse operation.

    In your other snippet you are using the peerCount expression, which will give you the index + 1 of the last entry. If a peer leaves it will upset your indexing scheme. Also because it's index + 1 you will likely get off by one lookup errors, so I would not recommend doing this.

  • Nepeo

    I understand what you are talking about, but I'm not so sure how to go about doing it. Could you maybe send a screenshot of how it works? ¯\_(ツ)_/¯

  • Hey sorry about the slow response. Haven't been on the forums for a couple of weeks.

    So I loaded up the Multiplayer chat room demo and it kinda does something similar to this already, except it uses a list object to contain and display the entries. I made the following adaptations so that it matches your requirements:

    1. Delete the PeerList object from the project

    2. Add a Dictionary object and rename it UserDictionary

    3. Add a text box to the Chat layout to the right of the chatbox where PeerList used to be ( with the same dimensions ).

    After this I added a new group to the Chat eventsheet with the following logic:

    Okay so theres 2 things going on here. First is we're tying into some events from the multiplayer plugin to update our Dictionary. The second is we're updating our textbox with the entries.

    To do the first we bind the event "on signalling joined room" to add our user ID and alias to the dictionary. Next we bind the event "on peer connected" to add other users to the dictionary. Then we bind "on peer disconnected" to remove users from the dictionary when they leave. Finally we bind "on kicked" which tells us we're not part of the room, so we should remove all the entries in the room.

    To update the textbox I created a small function that clears all the text, then appends a line for each entry in the userdictionary which is a combination of the key, the value and a newline. We're using the PeerID as the key, and the value we store in the PeerAlias. So we end up with something like "AAAA: User 1" for each user.

    I've validated this works as expected with users connecting and disconnecting. Hopefully you can recreate what I've done here with the demo, I believe it's doing everything you require.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Hi, sorry for the slow response as well. I haven't been on here for a while. I just read what you said and I will try it. Thank you.

  • I have tried it and it works, thank you :)

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)