ReeseR
ReeseR3w ago

Best way to sync data on a table?

I'm creating something similar to a bowling scoresheet: Each row is a different player and each column contains scores for each round. Right now I'm thinking about using a couple realtime arrays much like you would use 2 lists to store the data. However, the model for the inner array only contains a single int (and the outer one contains only an realtime array). I'm also not sure a RealtimeSet would work since the data isn't ordered? I hope I'm over-complicating this. Is there a better way to sync this kind of data?
4 Replies
kapa.ai
kapa.ai3w ago
Hi @ReeseR. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- For your use case, a RealtimeDictionary might be a better fit. According to the documentation (https://normcore.io/documentation/room/collections#non-transactional-collections), a RealtimeDictionary is commonly used to represent a model that can have fields that are dynamically added or removed at runtime. You could create a ScoreModel and store instances of it in a RealtimeDictionary using each player's clientID as the key. The ScoreModel could contain an array or list of integers representing the scores for each round. This way, you can easily add or remove scores for each player and keep everything in sync. Here's a simplified example of what the ScoreModel might look like:
public class ScoreModel : RealtimeModel {
// The scores for each round.
private RealtimeArray<int> _scores;

// Get the scores.
public RealtimeArray<int> Scores {
get { return _scores; }
}
}
public class ScoreModel : RealtimeModel {
// The scores for each round.
private RealtimeArray<int> _scores;

// Get the scores.
public RealtimeArray<int> Scores {
get { return _scores; }
}
}
And here's how you might use it with a RealtimeDictionary:
// Create a new RealtimeDictionary.
RealtimeDictionary<uint, ScoreModel> scoreDictionary = new RealtimeDictionary<uint, ScoreModel>();

// Add a new ScoreModel for a player.
ScoreModel playerScore = new ScoreModel();
scoreDictionary.Add(playerID, playerScore);

// Update a player's score.
playerScore.Scores.Add(score);
// Create a new RealtimeDictionary.
RealtimeDictionary<uint, ScoreModel> scoreDictionary = new RealtimeDictionary<uint, ScoreModel>();

// Add a new ScoreModel for a player.
ScoreModel playerScore = new ScoreModel();
scoreDictionary.Add(playerID, playerScore);

// Update a player's score.
playerScore.Scores.Add(score);
Remember, the RealtimeDictionary and ScoreModel would need to be properly set up to work with Normcore's synchronization system. This is just a simplified example to illustrate the concept. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai3w ago
<@806620207447146517> kapa.ai is still learning and improving, please let us know how it did by reacting below
ReeseR
ReeseR3w ago
RealtimeArray's can't be integers, only models? At least from what I'm reading in the docs: "RealtimeArray is a special model type that holds a sequential list of models that can be modified at runtime."
Mechabit
Mechabit3w ago
make a model with an int property and put that model into a realtime array you can nest arrays this way