v0.4.22中新版Request的使用说明与更新 #409
Notify-ctrl
announced in
Announcements
Replies: 1 comment
-
多人询问修改例修改前 for _, p in ipairs(players) do
p.request_data = json.encode(data)
p.default_reply = my_default_reply
end
room:notifyMoveFocus(players, focus_text)
room:doBroadcastRequest(command, players)
for _, p in ipairs(players) do
local reply_data
if p.reply_ready then
reply_data = json.decode(p.client_reply)
else
reply_data = p.default_reply
end
end 修改后: local req = Request:new(players, command)
req.focus_text = focus_text
for _, p in ipairs(players) do
req:setData(p, data)
req:setDefaultReply(p, my_default_reply)
end
for _, p in ipairs(players) do
local reply_data = req:getResult(p)
end 和之前一样,req中自动处理json相关,调用
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
随着 Qsgs-Fans/freekill-core@e3fe1aa 的更新,
Room:doRequest
、Room:doBroadcastRequest
和Room:doRaceRequest
三个函数面临淘汰,并将很快(大概就下个版本的时候)从Room中删除这几个函数。这一系列discussion用来说明新版Request中几个概念以及使用方法,以及使用例。相关源码:
https://github.com/Qsgs-Fans/freekill-core/blob/e3fe1aa629584ec61713946fe1dece5ede45031f/lua/server/network.lua
单人询问修改例
旧版代码:
新版代码:
可以看到旧版中穿插着json操作处理数据,而新版中数据的传输(
json.encode
)和接收(json.decode
)都在req:getResult(player)
中自动处理了。更多信息请查看源码中的注释。room:notifyMoveFocus
是用来在玩家下面显示“xxx 思考中”的文本的。Request将这一步整合到了询问内部,里面的focus_text默认显示command的内容,可以自己通过修改req.focus_text
自定义显示内容。Important
不要自己调用
json.encode
和json.decode
!把它们交给req去完成吧。如果本来就不需要进行encode或者decode,可以指定req的send_encode
或者receive_decode
属性为false
(一般来说这种情况很少)。Beta Was this translation helpful? Give feedback.
All reactions