Sign In Register

How can we help you today?

Start a new topic

Network Performance sending Event data

Hi,


I have a question, but I'll explain it as an example:


As a player I create a new item that has different properties.

When I create the item for the first time, I need to send all the properties through the LogEventRequest in order to save it.


Let say I need to send 15 properties (durability, strength, etc.) that are custom to the situation (can't use meta).


So the player adds it to his inventory. I create the request and send it to GS.

Fine, I've created a new LogEventRequest with 15 .SetEventAttribute.


The question is the following. When I for example just need to update the durability, should I create a new cloud event and use this new event to send the durability property? Or could I pass the full properties for the item?


Sending strings is still expensive right? So for example if the keys are long, is the weight of the "package" bigger? If I have 15 attributes instead of 5 (all strings for example) is it also better?


I find that sometimes I just want to update 1 property, but how do I know what I send on the cloud if the event is the same? Do I need to check all attributes to see if they are null or empty? and do not update them if so?


Thanks.


I´m having the same "issue" although I haven´t worked on it yet. I also feel bad sending 15 fields over the net when I only need 1.


I was thinking of creating two Events. CreateItem event with all X properties, and UpdateItem event, with the properties you want to update and the value, it can be only 1 property or more than one like:


"ItemID": "ItemToUpdateID",

"Updates": [{"Property2": value},{"Property8": value}]


Again, pretty new to GS so not sure if this is the way to go.

I would like to know if I need to create an event for secific updates (as I sometimes need to update different fields). I'ld like to know the cost of a full set of properties vs 2-3 properties.


Can someone from Support can help us?


Thanks!

 Hey guys,


Ivan I think your approach would be perfectly feasible, I would be inclined to have a single attribute set to a JSON object containing the properties in this circumstance given that the exact properties are unknown until runtime. This way I believe would satisfy your requirements Pr of having as you say a single property to update without having the cost of sending a lot of redundant data. I hope this helps.


Kind regards,

 - Steve

Hi Steve, 


Thanks for your answer. But I am wondering How you would do that? 

Could you give me an example?


I am not sure if you are actually talking about the same way of creating regular Event or is it something different? I'm quite new to all of this.


Thanks!



Yeah, I got a bit lost in "have a single attribute set to a JSON object containing the properties".


You mean what I did of having a single attribute "Updates" containing the properties in an array object? Or you mean a different JSON structure?


And about the properties being unknown until run-time I got a bit lost too. The Client and the server need to have the same attributes. If the server has the attribute "Speed:value" but you send "Sped:value" (missing one e) from the Client, then you will have problems in the cloud script trying to update that field. So you need to make sure both Client and Server speak the same language (have the same attribute names) and avoid typos.

 Hey guys,


Just to clarify I am talking about a regular event in this instance. You may have noticed the drop down when you are setting the type of attribute in an event, what I would do here is to utilize the JSON type, does this make sense so far? Then yes exactly Ivan you could have this single attribute called "Update" with it containing the properties in an object array or just a regular object with the keys as the property name. By unknown I don't mean entirely unknown rather I mean more along the line of not knowing what properties exactly you're going to be updating and at what time, does this make sense? I hope this helps.


Kind regards,

 - Steve

Ok, I get it. Thanks Steve. Thanks!


The only thing you need to do now Pr is to create the cloud script code for the UpdateItemEvent. 


If i'm not wrong it'd consist of the logEvent sent from your client, with the JSON with the structure I mentioned for example, then in the cloud script and in pseudo code:

  

var Json = GetScriptData(yada-yada) // read the JSON the client sent us

var ItemDocument = Spark.runtimeCollection('PlayerItems').find({"playerID":Spark.getPlayer().getPlayerId(),"itemID":Json.ItemID}); // get the Item document to update assuming it´s inside a collection called PlayerItems

var properties =Json.Updates //Get the properties you want to update, it can be 1 or several

foreach property in properties{ //Iterate through the properties of our Json
     ItemDocument.Update(property.name : property.value) // Update the item property
}

  Again this is pseudo code giving a general idea of what you should do. I would give you the code in MongoDB but I'm super new and I'm still struggling with MongoDB's syntax and functions. A "MongoDB update document" search in google should help you to write the real code.



Thank you Guys for your help.


Ivan, I actually used item.value = jsonData[key]; to update the value of my item.

Obviously you always need to know what you send and what you get, but I think this is acceptable.


I was able to make it work, but I still have freezes and lag in the editor when updating the value from Unity. I will create a new discussion as it's a different topic.


Thanks again!

Login to post a comment