我想在光子云上使用Hashtable發送數據,但確實收到了正確的eventCode的數據,但是鍵值對返回了一些隨機數。我的代碼是這樣的,同時發送數據: -在光子云上使用Hashtable發送數據
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'
?
請忽略最後一行。我忘了將事件代碼轉換爲int,所以它打印出char:/ – noob