RealtimeCallback(RealtimeModelEvent.OnDidReadProperties)
It seems that the RealtimeCallback always fires even if the RealtimeSet didn't change. This is the code i have:
8 Replies
Hi @Andrei Vaduva. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
The
RealtimeCallback
attribute with RealtimeModelEvent.OnDidReadProperties
is designed to fire after a model reads properties from a remote update. This means it will trigger every time there is a deserialization pass, regardless of whether the RealtimeSet
has changed or not.
If you want to trigger an event only when the RealtimeSet
changes, you might want to consider using the modelAdded
or modelRemoved
events provided by the RealtimeSet
class. These events fire when a model is added or removed locally or remotely.
Here is an example of how you might use these events:
In this example, the OnModelUpdatedHandler
event will only fire when a model is added or removed from the _rooms
RealtimeSet
.
Please note that this code is just an example and might need to be adjusted to fit your specific use case.
For more information, you can refer to the RealtimeSet<TValue> documentation (https://normcore.io/documentation/reference/classes/Normal.Realtime.Serialization.RealtimeSet%601) and the RealtimeModelEvent documentation (https://normcore.io/documentation/reference/classes/Normal.Realtime.RealtimeModelEvent).
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@1217086475661738045> kapa.ai is still learning and improving, please let us know how it did by reacting below
model added event doesn't fire if the contents of the set changes
a workaround is to add an int property next to the set which you can increment when there's a change
that's what i would expect. I'm trying to build a simple matchmaking system but i'm having trouble matching 2 users if they join the matchmaking room really quickly, in that case, they both create a room instead of one creating a room and one joining
i think i'll fix it with a random delay between 2 values and that's it 😄
not much you can do about 2 players creating a match at the same time
at least the 3rd player will have a choice of matches lol
or you can create a waiting for match queue
and only create a match when there's 2 people in the queue
hmm, that would work
with some time-out or start now button
and the lowest timestamped client will create the room and the other can join