MasterOX 水
MasterOX 水2w ago

how to handle code server side

how do i run a timer for example on the server and get a signal sent to all the clients when that timer reaches 0
5 Replies
kapa.ai
kapa.ai2w ago
Hi @MasterOX 水. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- In NormalVR, you can use the RealtimeComponent to synchronize data across all clients. However, it's important to note that NormalVR doesn't have a traditional server-client architecture where you can run code on the server. Instead, all clients are peers and they synchronize data with each other. For your specific case of a timer, you can create a RealtimeComponent that holds the start time of the timer. All clients can access this start time and calculate the elapsed time locally. When the timer reaches 0, you can handle this event locally on each client. Here's an example of how you can create a stopwatch using a RealtimeComponent:
using Normal.Realtime;

public class Stopwatch : RealtimeComponent<StopwatchModel> {
public float time {
get {
// Return 0 if we're not connected to the room yet.
if (model == null) return 0.0f;

// Make sure the stopwatch is running
if (model.startTime == 0.0) return 0.0f;

// Calculate how much time has passed
return (float)(realtime.room.time - model.startTime);
}
}

public void StartStopwatch() {
model.startTime = realtime.room.time;
}
}
using Normal.Realtime;

public class Stopwatch : RealtimeComponent<StopwatchModel> {
public float time {
get {
// Return 0 if we're not connected to the room yet.
if (model == null) return 0.0f;

// Make sure the stopwatch is running
if (model.startTime == 0.0) return 0.0f;

// Calculate how much time has passed
return (float)(realtime.room.time - model.startTime);
}
}

public void StartStopwatch() {
model.startTime = realtime.room.time;
}
}
In this example, realtime.room.time is a synchronized clock that matches the room server's clock exactly with no added latency. You can start the stopwatch by calling StartStopwatch(), and you can get the elapsed time by accessing the time property. When the timer reaches 0, you can handle this event locally on each client. For example, you can check if time is 0 in your game loop, and if it is, you can trigger whatever event you want. For more information, you can refer to the Timers + Synchronized Playback (https://normcore.io/documentation/guides/recipes/timers-and-synchronized-playback) guide in the NormalVR documentation. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai2w ago
<@758040514678489279> kapa.ai is still learning and improving, please let us know how it did by reacting below
MasterOX 水
MasterOX 水2w ago
so models are data stored on the server, accesible by all clients? @Normcore Assistant
kapa.ai
kapa.ai2w ago
Let me check the knowledge base for you. One moment! :books: ---------------------- Yes, that's correct. In NormalVR, models are used to store and synchronize data across all clients. Each model in the datastore, including child models, can have an owner with which it is associated. By default, a model has an ownerID of -1, which denotes that it has no owner. When a model is unowned, it can be modified by anyone in the room. However, when a model is owned by a client, the server only lets the owning client make changes to it or to any of its child models. The datastore is a collection of RealtimeModel objects. These objects make up all of the synchronized states of your application. The root-level model in the datastore is the roomModel that's passed to Room.Connect(). Any models that are not part of realtime components that you would like to store in the datastore need to be a child of this model. For more information, you can refer to the Datastore (https://normcore.io/documentation/room/datastore) and Ownership (https://normcore.io/documentation/room/ownership-and-lifetime-flags) sections in the NormalVR documentation. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai2w ago
<@758040514678489279> kapa.ai is still learning and improving, please let us know how it did by reacting below
More Posts
What is the best way to get the exact time a room is created?Is there a way to find the room start time?Bandwidth usage analysisI wanted to analyze my application's bandwidth usage more thoroughly to see if I'm sending unnecessaAllow RealtimeView.realtime and RealtimeView.viewUUID to be set from the editor inside prefabsWe have a use case where we want to be able to dynamically spawn a normcore room from a prefab. UnfoRealtime.Destroy On owned realtime prefabs.Can I destroy a RealtimePrefab by calling Realtime.Destroy even if someone else is an owner? Or do IHow can I distort the mic audio in RealtimeAvatarVoice to be higher or lower pitch?Is it possible to distort the mic audio from RealtimeAvatarVoice so the player is heard with a squeaAre there any best practices for syncing a large number of variables in one script?For instance if we have a large script with many bools floats, integers etc and they all need to be First player isn't synced to other players, while other players are visible to the first playerNo idea why this started happening - didn't change any code from what I can tell, but now whenever aReadStream was expecting to read a Null type from the stream, but was asked to read a Model typeI started getting this error in my game when I started disconnecting from it by closing the app. My Show the property path for RealtimeSet delta update errorsSometimes I'll get an error from normcore like `RealtimeSet received delta update for non-existent kHow can I disconnect another player from the gameI need to disconnect a player with another player. Can I do that?