x


Which data structure to hold Array of Array (Unity Javascript) in Unity C#?

I have an array of array of message that I need to send to the server, Unfortunately, I need to code the server module on C#. So what I'm asking is which data structure should correspond to this data structure

My code is more or less as such:

//Javascript part on the game engine
var actionMsg1 : Array = new Array();
var actionMsg2 : Array = new Array();
var actionMsg3 : Array = new Array();

actionMsg1.Push("object A");
actionMsg1.Push("Move");
actionMsg1.Push("tile [2,2]");

actionMsg1.Push("object A");
actionMsg1.Push("shoot");
actionMsg1.Push("object B");

var arrMovementMsg : Array = new Array();
arrMovementMsg.Push(actionMsg1);
arrMovementMsg.Push(actionMsg1);

msgPacker.PackMessage(arrMovementMsg);

Now msgPacker's clas is the class written in C#, so I'm confused how I'm gonna make the method signature for it? I definitely can't make

public PackMessage(Array arrMovementMsg)

on the script, since C# doesn't have Array class. So which data type should I use to correspond to the data type array in javascript? Do I have any other choice than reworking on the game engine's message system so that It process an array of string? (

more ▼

asked Sep 12 '11 at 06:29 AM

Solitude01 gravatar image

Solitude01
61 8 11 12

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

Google msdn csharp List

more ▼

answered Sep 12 '11 at 06:38 AM

DaveA gravatar image

DaveA
26.5k 151 171 256

(comments are locked)
10|3000 characters needed characters left

You could write

List<List<string>> lstMovementMsg = new List<List<string>>();
List<string> actionMsg = new List<string>();
actionMessage.Add("object A");
actionMessage.Add("shoot");
actionMessage.Add("object B");
lstMovementMsg.Add(actionMessage);

But if I were you I'd use another approach to pack messages and send them over the network. You should checkout the Network View from Unity and the RPC functioanlity that you can use.

more ▼

answered Sep 12 '11 at 08:53 AM

alexvda gravatar image

alexvda
61 3 3 5

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1359
x108
x69

asked: Sep 12 '11 at 06:29 AM

Seen: 889 times

Last Updated: Sep 12 '11 at 08:53 AM