包,函数的冲突


Packet & Function Conflict

我回来了,这次我在制作一款游戏时遇到了一个问题。所以我追踪了一些信息包,在我的信息源上复制了一份。因此,函数:

function handleBakeryStateUpdate( $data, $str, $clientid )
{
    $client    = $this->clients[ $clientid ]; //$client SHOULD ALWAYS BE A MEMBER OF THE CLIENT CLASS!
    $this->sendToRoom( $client->extRoomID, "%xt%barsu%" . $client->ID . "%"{'CurrentStation':'IngredientsStation','IngredientsStation':[{'IngredientType':'Eggs','TotalRequired':1,'CurrentCount':0},{'IngredientType':'Milk','TotalRequired':1,'CurrentCount':0},{'IngredientType':'Hay','TotalRequired':1,'CurrentCount':0},{'IngredientType':'Flour','TotalRequired':1,'CurrentCount':0}],'CheerStation':{'CheerCapacity':7,'CurrentCheerCount':7,'Emote':7},'MultiplierStation':{'Counter':-1,'Multiplier':'Small'}}"%" );
}

数据包应该发送一堆东西,在该数据包中它有{和}。另一个问题是这个函数还有{和}。所以它给了我:

PHP Parse error:  syntax error, unexpected '{' in ...

我该如何解决这个问题?

更多信息:它正在发送的数据包是所有这些:

{'CurrentStation':'IngredientsStation','IngredientsStation':[{'IngredientType':'Eggs','TotalRequired':1,'CurrentCount':0},{'IngredientType':'Milk','TotalRequired':1,'CurrentCount':0},{'IngredientType':'Hay','TotalRequired':1,'CurrentCount':0},{'IngredientType':'Flour','TotalRequired':1,'CurrentCount':0}],'CheerStation':{'CheerCapacity':7,'CurrentCheerCount':7,'Emote':7},'MultiplierStation':{'Counter':-1,'Multiplier':'Small'}}

谢谢。

如果您只是想将JSON作为封装在百分比符号中的字符串传递,则:

function handleBakeryStateUpdate( $data, $str, $clientid )
{
    $client    = $this->clients[ $clientid ]; //$client SHOULD ALWAYS BE A MEMBER OF THE CLIENT CLASS!
    $this->sendToRoom( $client->extRoomID, "%xt%barsu%" . $client->ID . "%" . "{'CurrentStation':'IngredientsStation','IngredientsStation':[{'IngredientType':'Eggs','TotalRequired':1,'CurrentCount':0},{'IngredientType':'Milk','TotalRequired':1,'CurrentCount':0},{'IngredientType':'Hay','TotalRequired':1,'CurrentCount':0},{'IngredientType':'Flour','TotalRequired':1,'CurrentCount':0}],'CheerStation':{'CheerCapacity':7,'CurrentCheerCount':7,'Emote':7},'MultiplierStation':{'Counter':-1,'Multiplier':'Small'}}" . "%" );
}

我有点怀疑这是不是你想要的,但除非你能证明sendToRoom的期望,这是我能给出的最好的答案。

还要注意,使用"packet"的方式是非常令人困惑的。你只是把一个字符串传递给一个函数。"包"这个词的用法令人困惑,因为它在网络中有一个非常具体的含义。