MaxEsin
MaxEsin3w ago

Can I get a list of all created rooms which are currently running?

My app generates a 6 digit room's name each time when room is created. I need to exclude a chance to generate a name that's already occupied and regenerate it again.
9 Replies
kapa.ai
kapa.ai3w ago
Hi @MaxEsin. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Based on the information provided in the knowledge sources, I can answer your question about getting a list of all created rooms which are currently running in NormalVR's Normcore platform. Unfortunately, according to the Architecture > Common Questions document, there is currently no built-in functionality in Normcore to get a list of all rooms and how many players are in them. The documentation states: "This is something we're working on, but for the time being, it's something you'll need to manage yourself." This means that Normcore does not currently provide a direct way to retrieve a list of all created rooms or check if a specific room name is already in use. Given this limitation, you would need to implement your own solution to manage room names and avoid duplicates. Here are a few suggestions you could consider: 1. Maintain your own database or server-side list of created room names. 2. Use a significantly larger number space for room names (e.g., 8 or 10 digit codes) to reduce the likelihood of collisions. 3. Implement a system where you attempt to connect to a room with the generated name, and if it already exists, generate a new name and try again. Keep in mind that these are workarounds and may not be ideal for all use cases. The Normcore team seems to be aware of this limitation and is working on a solution, so you might want to keep an eye on future updates to the platform. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai3w ago
<@328247194794852352> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
Mechabit
Mechabit3w ago
unity lobby
MaxEsin
MaxEsinOP2w ago
@Normcore Assistant Give me an example of using RealtimeDictionary
kapa.ai
kapa.ai2w ago
Let me check the knowledge base for you again. One moment! :books: ---------------------- Certainly! I can provide you with an example of using RealtimeDictionary in Normcore. RealtimeDictionary is one of the collection types provided by Normcore for synchronizing data in real-time. According to the Room > Collections documentation: RealtimeDictionary works similarly to Dictionary<uint, ModelType>. It is commonly used to represent a model that can have fields that are dynamically added or removed at runtime. Here's an example of how you might use RealtimeDictionary to store player scores:
using Normal.Realtime;
using Normal.Realtime.Serialization;

[RealtimeModel]
public class ScoreboardModel
{
[RealtimeProperty(1, true)]
private RealtimeDictionary<int> _playerScores;

public RealtimeDictionary<int> playerScores
{
get => _playerScores;
set => _playerScores = value;
}
}

public class Scoreboard : RealtimeComponent<ScoreboardModel>
{
public void AddScore(uint playerID, int score)
{
model.playerScores[playerID] = score;
}

public int GetScore(uint playerID)
{
if (model.playerScores.ContainsKey(playerID))
{
return model.playerScores[playerID];
}
return 0;
}
}
using Normal.Realtime;
using Normal.Realtime.Serialization;

[RealtimeModel]
public class ScoreboardModel
{
[RealtimeProperty(1, true)]
private RealtimeDictionary<int> _playerScores;

public RealtimeDictionary<int> playerScores
{
get => _playerScores;
set => _playerScores = value;
}
}

public class Scoreboard : RealtimeComponent<ScoreboardModel>
{
public void AddScore(uint playerID, int score)
{
model.playerScores[playerID] = score;
}

public int GetScore(uint playerID)
{
if (model.playerScores.ContainsKey(playerID))
{
return model.playerScores[playerID];
}
return 0;
}
}
In this example: 1. We define a ScoreboardModel with a RealtimeDictionary<int> to store player scores. 2. The Scoreboard component provides methods to add and get scores for players. 3. Player IDs (of type uint) are used as keys, and their scores (of type int) are the values. You could use this in your game like this:
public class GameManager : MonoBehaviour
{
private Scoreboard _scoreboard;

private void Awake()
{
_scoreboard = GetComponent<Scoreboard>();
}
public void PlayerScored(uint playerID, int points)
{
int currentScore = _scoreboard.GetScore(playerID);
_scoreboard.AddScore(playerID, currentScore + points);
}
}
public class GameManager : MonoBehaviour
{
private Scoreboard _scoreboard;

private void Awake()
{
_scoreboard = GetComponent<Scoreboard>();
}
public void PlayerScored(uint playerID, int points)
{
int currentScore = _scoreboard.GetScore(playerID);
_scoreboard.AddScore(playerID, currentScore + points);
}
}
This example demonstrates how RealtimeDictionary can be used to dynamically add and update player scores in a networked game. The scores will automatically synchronize across all connected clients. Remember, as mentioned in the Room > Common Questions document, RealtimeDictionary is provided by Normcore because standard C# collections like Dictionary<> don't automatically notify Normcore when their contents change, making it difficult to detect and sync changes automatically. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai2w ago
<@328247194794852352> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
MaxEsin
MaxEsinOP2w ago
@Normcore Assistant can i make my own class and store it in the RealtimeDictionary or should I use only primitives?
kapa.ai
kapa.ai2w ago
Let me check the knowledge base for you again. One moment! :books: ---------------------- Yes, you can store your own custom class in a RealtimeDictionary, but there are some important considerations and requirements to keep in mind. According to the Room > Supported Primitives documentation, RealtimeDictionary can store RealtimeModel objects. This means you can create your own custom class, but it needs to be a RealtimeModel. Here's how you can do this: 1. First, create your custom class as a RealtimeModel:
[RealtimeModel]
public partial class MyCustomClass
{
[RealtimeProperty(1, true)]
private string _name;

[RealtimeProperty(2, true)]
private int _score;

// Add more properties as needed
}
[RealtimeModel]
public partial class MyCustomClass
{
[RealtimeProperty(1, true)]
private string _name;

[RealtimeProperty(2, true)]
private int _score;

// Add more properties as needed
}
2. Then, you can use this custom class in a RealtimeDictionary:
[RealtimeModel]
public partial class MyContainerModel
{
[RealtimeProperty(1, true)]
private RealtimeDictionary<MyCustomClass> _customObjects;
}
[RealtimeModel]
public partial class MyContainerModel
{
[RealtimeProperty(1, true)]
private RealtimeDictionary<MyCustomClass> _customObjects;
}
3. You can then use this in a RealtimeComponent:
public class MyComponent : RealtimeComponent<MyContainerModel>
{
public void AddCustomObject(uint key, string name, int score)
{
MyCustomClass customObject = new MyCustomClass();
customObject.name = name;
customObject.score = score;
model.customObjects[key] = customObject;
}
}
public class MyComponent : RealtimeComponent<MyContainerModel>
{
public void AddCustomObject(uint key, string name, int score)
{
MyCustomClass customObject = new MyCustomClass();
customObject.name = name;
customObject.score = score;
model.customObjects[key] = customObject;
}
}
It's important to note that you should not use standard C# classes or structs directly in RealtimeDictionary. As mentioned in the Room > Common Questions document: "Only supported primitives (int, float, Vector3, string, etc.) can be serialized, so if you need to sync a specific kind of object like a TextMesh Pro object, you should create a field for each property on the object that you'd like to sync." This means that if you want to store complex objects, you need to create a RealtimeModel that represents the data you want to synchronize. Remember, RealtimeModels are designed to synchronize data that can be easily serialized and transmitted to other clients. If you need to store complex objects or large amounts of data, you might need to consider alternative approaches or break down your data into smaller, synchronizable pieces. Room > Supported Primitives Room > Common Questions ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai2w ago
<@328247194794852352> Kapa.ai is still learning and improving, please let me know how I did by reacting below.

Did you find this page helpful?