I am trying to send data using Hashtable on photon cloud, I do receive the data with correct eventCode, but the key-value pair returns some random numbers. My code is like this while sending data:-

void NetworkLogic::sendEvent(void)
{
    ExitGames::Common::Hashtable* table =new ExitGames::Common::Hashtable;
        table->put<int,int>(4,21);
        const ExitGames::Common::Hashtable temp = (const ExitGames::Common::Hashtable)*table;//= new ExitGames::Common::Hashtable;
        mLoadBalancingClient.opRaiseEvent(false, temp, 100);
}

While receiving data, the code is like this:-

void NetworkLogic::customEventAction(int playerNr, nByte eventCode, const ExitGames::Common::Hashtable& eventContent)
{
    // you do not receive your own events, unless you specify yourself as one of the receivers explicitly, so you must start 2 clients, to receive the events, which you have sent, as sendEvent() uses the default receivers of opRaiseEvent() (all players in same room like the sender, except the sender itself)
    PhotonPeer_sendDebugOutput(&mLoadBalancingClient, DEBUG_LEVEL_ALL, L"");
    cout<<((int)(eventContent.getValue(4)));
}

What I get printed on console is some random values or int, while it should be 21. What am I doing wrong here?

Edit:
In customEventAction() when I used the following statement:

cout<<eventContent.getValue(4)->getType()<<endl;
cout<<"Event code = "<<eventCode<<endl;

I got the following output:

i
Event code = d

I searched and found that 'i' is the value of EG_INTEGER which means the value I am sending is getting received properly. I am just not been able to convert it back to int. And why the event code is coming as 'd'?

有帮助吗?

解决方案

eventContent.getValue(4)

returns an Object. You can't simply cast that Object to int, but have to access the int value inside it:

if(eventContent.getValue(4))
            myInt = ExitGames::Common::ValueObject<int>(eventContent.getValue(4)).getDataCopy();
cout << myInt;
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top