【发布时间】:2012-12-10 12:50:59
【问题描述】:
我正在尝试使用光子云上的 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'?
【问题讨论】:
-
请忽略最后一行。我忘记将事件代码转换为 int,所以它正在打印 char :/
标签: c++ cloud marmalade photon