[C#] What kind of data can i send from client -> server through TriggerServerEvent?

So i have a List that i want to send from the client to the server, but i can’t get it to work. I have tried putting putting it in an ExpandoObject (both as list and as array), throws exception.
I’ve tried covnerting it to float[,] and sending it that way, throws exception. Yesterday i tried every combination i could think of but it doesn’t want to work.

So, if you had a list or array of Vector3 to send from client->server or server->client, how would you do it?

  • All basic data types: string, int, float and the likes.
  • IDictionary, IList, etc.
  • Delegates as CallbackDelegate
  • Use dynamic when recieving for more complex objects.
  • If you are lazy and do not want to work this out, you can use Newtonsoft JSON to Serialize / Deserialize; Don’t do this.

So you can’t send arrays? That’s unfortunate.

My current approach for sending the data is the following:
In client i first flatten the list of vector3 into a list of floats 3x the length.
I then pass that list when i trigger the server event.
Then in the server i use: private void TestEvent([FromSource]Player player, dynamic testData).
Now i cast the testData to IList and when i want to access the float values i cast them from object to float.

Is this a reasonable appproach? It’s a little tedious and it would suck if i had to send more complicated data.

Edit: So i’ve tested this some more and you can send an array just fine, but you send it as dynamic and cast it to a List, then cast those objects the same way you would if you’re sending a list. It’s strange that an array gets type of list though.

Not sure if you can send arrays, but it is not really an issue if you can’t as you got linq.

Just go .ToList if it does not work. also

private void TestEvent([FromSource]Player player, IList<float> testData)

works

I’m trying to do private void TestEvent([FromSource]Player player, IList testData) and it refuses to work. However if i use IList then it works as it should.

float[] floatArray = {1f, 2f, 3f};
TriggerServerEvent("GimmeFloats", floatArray.ToList());

private void GimmeFloats([FromSource]Player player, IList<float> testData)

should work. If the name is actually trigger server event :wink:

I’m doing:
int[] vars = { 1, 2, 3, 4 };
List<int> list = vars.ToList();
TriggerServerEvent(“testEvent”, list);
and then on server:
private void TestEvent([FromSource]Player player, IList<int> testData)
And it throws exception

IList<int> maybe specify what type of content you want in the list.

I do, it got lost in the forum formating

work with the system, not against it - don’t try any fixed typing for data obtained from serialization, just use dynamic until the data is parsed