在光子云上使用哈希表发送数据
Sending data using Hashtable on Photon Cloud
>我正在尝试使用光子云上的哈希表发送数据,我确实使用正确的事件代码接收数据,但键值对返回一些随机数。发送数据时我的代码是这样的:-
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;
相关文章:
- 有没有一种方法可以创建一个带有哈希表的数据库,该哈希表具有恒定时间查找功能
- 如何将这个C++哈希表转换为动态扩展和收缩,而不是使用硬设置的最大值
- 用C++将哈希表写入文件并从文件中恢复
- C++中的并发哈希表
- 在具有开放寻址的哈希表中插入节点 [优化逻辑]
- 与C++哈希表的基础知识混淆
- 调整大小和复制哈希表数组中的元素
- 带链接的基本哈希表
- C++哈希表中,两个相同的实现,但一个给出错误
- 如果索引不是整数,我们如何在 C++ 中插入哈希表
- C++哈希表 - 如何解决自定义数据类型作为键的unordered_map冲突?
- 实现具有浮点键的类似哈希表的数据结构,其中公差内的值被合并在一起
- 使用对数据类型的向量的哈希表中的分段错误错误
- 名称和伪ID的数据结构:使用哈希表或bst
- 在光子云上使用哈希表发送数据
- 哈希表(数据结构)
- 如何存储需要随机选择和删除的数据,矢量,哈希表或其他
- 在2D哈希表中正确索引数据
- 对于哈希表,通常使用哪些数据结构来保存哈希表
- 哈希表线性探测数据结构