How to send a struct with PunTurnManager

Hi, I'm making a turnbased card game, I make all mechanics of the game, but I can't send the struct that includes the deck, the hand for each player , the cards in the table. The hand are a struc that includes a vector of another struct, I try to send with a instruction like this : "this.turnmanager.sendmove(MessageStruct);", but I can't send and receive it, so my question is: how I can send all struct? Or is it impossible to send?

there is the code of the structs:


struct cards
{
internal string value, suit;
}

struct hand
{
cards[] hand;
bool finishedcard; // for verify if the hand is empy
}

struct Message
{
List Table;
List Deck;
Hand LocalPlayer, RemotePlayer;
Stack StackLocal, StackRemote;
}

Message CardPack;

public void MakeTurn()
{
this.turnmanager.sendmove(CardPack);
}


thanks for the answer

Answers

  • sorry for the bad english and the identation but i,' m writing from a phone
  • Hi @Shuba_sa,

    if you want to send custom types you have to register those. The Serialization in Photon documentation page has an example how Vector2 is serialized in Photon.

    However I'm not sure if the way you are planing to synchronize the game is a good idea at all. Another idea that I have been thinking of is the following: if those cards have unique IDs, you can send an int array instead, which contains those IDs. In this case you don't have to register custom types.
  • public static readonly byte[] memVector2 = new byte[2 * 4];


    The doc Report this, but a doubt arose, the 2*4 is for the lenght right?

    And once I've serialized the struct, can I send this with Turnmanger.SendMove() functions?

    like: Message CardPack;

    public void MakeTurn()
    {
    this.turnmanager.sendmove(CardPack);
    }

    and in this instruction:
    PhotonPeer.RegisterType(typeof(Vector2), (byte)'W', SerializeVector2, DeserializeVector2);

    the "W" what it means?
  • So I wanna Serialize this class can anyone resolve my problem, it's very urgent..


    struct card
    {
    internal string suit;
    internal string value;
    }

    struct Hand
    {
    internal carta[] hand;
    internal bool[] FinishedCards;
    }

    struct Message
    {
    internal Hand Local, Remote;
    internal List Table, Deck;
    internal List StackLocal, StackRemote;
    }
  • The doc Report this, but a doubt arose, the 2*4 is for the lenght right?


    A Vector2 consists of 2 float values with 4 bytes each, so 2 x 4 is basically the size of the Vector2 object.

    the "W" what it means?


    It's a byte code for this type. In this case it's most likely 'W' because 'V' is used for Vector3 as you can see in the CustomTypes class which is included in the PUN package.

    Serializing your class requires a lot of effort because you have lots of data, especially dynamic length data like those Lists, whereat I don't know if it is necessary to serialize all of the data. However in my opinion you should think of another solution like I already mentioned in my first post.
Sign In or Register to comment.