在光子云上使用哈希表发送数据

Sending data using Hashtable on Photon Cloud

本文关键字:哈希表 数据 云上      更新时间:2023-10-16

>我正在尝试使用光子云上的哈希表发送数据,我确实使用正确的事件代码接收数据,但键值对返回一些随机数。发送数据时我的代码是这样的:-

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);
}

在接收数据时,代码是这样的:-

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)));
}

我在控制台上打印的是一些随机值或整数,而它应该是 21。我在这里做错了什么?

编辑:
customEventAction(),当我使用以下语句时:

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

我得到了以下输出:

i
Event code = d

我搜索并发现'i'EG_INTEGER的值,这意味着我发送的值正在正确接收。我只是无法将其转换回int.为什么事件代码会'd'

eventContent.getValue(4)

返回一个对象。你不能简单地将该对象强制转换为 int,而必须访问其中的 int 值:

if(eventContent.getValue(4))
            myInt = ExitGames::Common::ValueObject<int>(eventContent.getValue(4)).getDataCopy();
cout << myInt;