1

我正在尝试在光子云上使用 Hashtable 发送数据,我确实收到了带有正确 eventCode 的数据,但是键值对返回了一些随机数。我的代码在发送数据时是这样的:-

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

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

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

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

我得到以下输出:

i
Event code = d

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

4

1 回答 1

2
eventContent.getValue(4)

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

if(eventContent.getValue(4))
            myInt = ExitGames::Common::ValueObject<int>(eventContent.getValue(4)).getDataCopy();
cout << myInt;
于 2012-12-11T19:25:06.723 回答