HaRrY
HaRrY5mo ago

How to clear RealtimeArray?

I am using RealtimeArrays to store RealtimeModels for scoring like kills/deaths etc. There is a use-case where I need to reset the scores and everything. How do I clear/remove all elements of RealtimeArray to start from scratch?
Solution:
you can store the realtime array inside a realtime set in order to clear your scores and create a new array
Jump to solution
3 Replies
kapa.ai
kapa.ai5mo ago
Hi @Harris Saleem. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- I'm sorry, but according to the documentation (https://normcore.io/documentation/room/collections#realtimearray), RealtimeArray in NormalVR only supports adding elements and does not support removing items by index. This is because the contents are sorted by index and the server cannot correctly solve merge-conflicts if two clients attempt to remove an object at an index at the same time. If you need a sorted collection that supports random removal, it is recommended to use either RealtimeDictionary with the key as the item index, or a RealtimeSet of models that can be sorted deterministically on all clients when the contents change. For storing data like health and scores, it is suggested to use a RealtimeDictionary or a StringKeyDictionary as mentioned here (https://normcore.io/documentation/realtime/common-questions#im-trying-to-store-my-players-health-in-a-realtimecomponent-on-my-avatar-how-can-i-let-other-players-modify-this-values-or-others). If you need to reset the scores and everything, you might need to create a new RealtimeArray and replace the old one. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai5mo ago
<@250518782341021697> kapa.ai is still learning and improving, please let us know how it did by reacting below
Solution
Mechabit
Mechabit5mo ago
you can store the realtime array inside a realtime set in order to clear your scores and create a new array