Lua接口/任务变量:修订间差异

来自天龙知识库
跳到导航跳到搜索
雪舞​(留言 | 贡献)
维护服务端 Lua 接口:核对参数、返回值、边界条件与调用示例
Waylee​(留言 | 贡献)
维护服务端 Lua 接口:核对参数、返回值、边界条件与调用示例
第1行: 第1行:
__NOTOC__
__NOTOC__
<div class="lua-reference" style="max-width:1200px;margin:0 auto;line-height:1.8;color:#29343a;font-family:Arial,'Microsoft YaHei',sans-serif;letter-spacing:0;overflow-wrap:anywhere;">
<div class="lua-reference">
[[首页|首页]] · [[Lua接口/服务端函数索引|服务端接口]] · [[Lua接口/服务端调用约定|调用约定]]
[[首页|首页]] · [[Lua接口/服务端函数索引|服务端接口]] · [[Lua接口/服务端调用约定|调用约定]]


第6行: 第6行:


== 任务参数 ==
== 任务参数 ==
{| class="wikitable" style="width:100%;table-layout:fixed;border-collapse:collapse;font-size:13px;"
{| class="wikitable"
! scope="col" style="text-align:left;background:#edf3f2;padding:8px;" | 接口
! scope="col" | 接口
! scope="col" style="text-align:left;background:#edf3f2;padding:8px;" | 参数与返回
! scope="col" | 参数与返回
|-
|-
| style="padding:8px;vertical-align:top;overflow-wrap:anywhere;" | [[Lua接口/服务端/GetMissionParam|GetMissionParam]]
| [[Lua接口/服务端/GetMissionParam|GetMissionParam]]
| style="padding:8px;vertical-align:top;overflow-wrap:anywhere;" | <code style="white-space:normal;overflow-wrap:anywhere;">sceneId, selfId, misIndex, paramIndex</code> → 参数值;0 或 -1 表示未设置或失败。
| <code>sceneId, selfId, misIndex, paramIndex</code> → 参数值;0 或 -1 表示未设置或失败。
|-
|-
| style="padding:8px;vertical-align:top;overflow-wrap:anywhere;" | [[Lua接口/服务端/SetMissionByIndex|SetMissionByIndex]]
| [[Lua接口/服务端/SetMissionByIndex|SetMissionByIndex]]
| style="padding:8px;vertical-align:top;overflow-wrap:anywhere;" | <code style="white-space:normal;overflow-wrap:anywhere;">sceneId, selfId, misIndex, paramIndex, value</code>;无返回值。
| <code>sceneId, selfId, misIndex, paramIndex, value</code>;无返回值。
|-
|-
| style="padding:8px;vertical-align:top;overflow-wrap:anywhere;" | [[Lua接口/服务端/GetMissionParamEx|GetMissionParamEx]]
| [[Lua接口/服务端/GetMissionParamEx|GetMissionParamEx]]
| style="padding:8px;vertical-align:top;overflow-wrap:anywhere;" | <code style="white-space:normal;overflow-wrap:anywhere;">sceneId, selfId, missionIndex, paramIndex, byteIndex</code> → 字节值;0 或 -1。
| <code>sceneId, selfId, missionIndex, paramIndex, byteIndex</code> → 字节值;0 或 -1。
|-
|-
| style="padding:8px;vertical-align:top;overflow-wrap:anywhere;" | [[Lua接口/服务端/SetMissionParamByIndexEx|SetMissionParamByIndexEx]]
| [[Lua接口/服务端/SetMissionParamByIndexEx|SetMissionParamByIndexEx]]
| style="padding:8px;vertical-align:top;overflow-wrap:anywhere;" | <code style="white-space:normal;overflow-wrap:anywhere;">sceneId, selfId, missionIndex, paramIndex, byteIndex, value</code>;无返回值。
| <code>sceneId, selfId, missionIndex, paramIndex, byteIndex, value</code>;无返回值。
|}
|}
[[Lua接口/服务端/GetMissionParam|GetMissionParam]] 按任务索引和参数索引读取整数值;[[Lua接口/服务端/GetMissionParamEx|GetMissionParamEx]] 进一步按字节索引读取参数中的指定字节。[[Lua接口/服务端/SetMissionByIndex|SetMissionByIndex]]、[[Lua接口/服务端/SetMissionParamByIndexEx|SetMissionParamByIndexEx]] 都无返回值。
[[Lua接口/服务端/GetMissionParam|GetMissionParam]] 按任务索引和参数索引读取整数值;[[Lua接口/服务端/GetMissionParamEx|GetMissionParamEx]] 进一步按字节索引读取参数中的指定字节。[[Lua接口/服务端/SetMissionByIndex|SetMissionByIndex]]、[[Lua接口/服务端/SetMissionParamByIndexEx|SetMissionParamByIndexEx]] 都无返回值。


== 全局数据块 ==
== 全局数据块 ==
{| class="wikitable" style="width:100%;table-layout:fixed;border-collapse:collapse;font-size:13px;"
{| class="wikitable"
! scope="col" style="text-align:left;background:#edf3f2;padding:8px;" | 接口
! scope="col" | 接口
! scope="col" style="text-align:left;background:#edf3f2;padding:8px;" | 参数与返回
! scope="col" | 参数与返回
|-
|-
| style="padding:8px;vertical-align:top;overflow-wrap:anywhere;" | [[Lua接口/服务端/GetMissionData|GetMissionData]]
| [[Lua接口/服务端/GetMissionData|GetMissionData]]
| style="padding:8px;vertical-align:top;overflow-wrap:anywhere;" | <code style="white-space:normal;overflow-wrap:anywhere;">sceneId, selfId, nIndex</code> → 数据值;失败 -1。
| <code>sceneId, selfId, nIndex</code> → 数据值;失败 -1。
|-
|-
| style="padding:8px;vertical-align:top;overflow-wrap:anywhere;" | [[Lua接口/服务端/SetMissionData|SetMissionData]]
| [[Lua接口/服务端/SetMissionData|SetMissionData]]
| style="padding:8px;vertical-align:top;overflow-wrap:anywhere;" | <code style="white-space:normal;overflow-wrap:anywhere;">sceneId, selfId, nIndex, nData</code>;无返回值。
| <code>sceneId, selfId, nIndex, nData</code>;无返回值。
|}
|}
全局数据块是跨任务共享的玩家数据,按 nIndex 索引读写。[[Lua接口/服务端/SetMissionData|SetMissionData]] 无返回值。
全局数据块是跨任务共享的玩家数据,按 nIndex 索引读写。[[Lua接口/服务端/SetMissionData|SetMissionData]] 无返回值。


== 临时缓存 ==
== 临时缓存 ==
{| class="wikitable" style="width:100%;table-layout:fixed;border-collapse:collapse;font-size:13px;"
{| class="wikitable"
! scope="col" style="text-align:left;background:#edf3f2;padding:8px;" | 接口
! scope="col" | 接口
! scope="col" style="text-align:left;background:#edf3f2;padding:8px;" | 参数与返回
! scope="col" | 参数与返回
|-
|-
| style="padding:8px;vertical-align:top;overflow-wrap:anywhere;" | [[Lua接口/服务端/GetMissionCacheData|GetMissionCacheData]]
| [[Lua接口/服务端/GetMissionCacheData|GetMissionCacheData]]
| style="padding:8px;vertical-align:top;overflow-wrap:anywhere;" | <code style="white-space:normal;overflow-wrap:anywhere;">sceneId, selfId, nIndex</code> → 缓存值;部分分支无返回值。
| <code>sceneId, selfId, nIndex</code> → 缓存值;部分分支无返回值。
|-
|-
| style="padding:8px;vertical-align:top;overflow-wrap:anywhere;" | [[Lua接口/服务端/SetMissionCacheData|SetMissionCacheData]]
| [[Lua接口/服务端/SetMissionCacheData|SetMissionCacheData]]
| style="padding:8px;vertical-align:top;overflow-wrap:anywhere;" | <code style="white-space:normal;overflow-wrap:anywhere;">sceneId, selfId, nIndex, nData</code>;部分分支无返回值。
| <code>sceneId, selfId, nIndex, nData</code>;部分分支无返回值。
|-
|-
| style="padding:8px;vertical-align:top;overflow-wrap:anywhere;" | [[Lua接口/服务端/ResetMissionCacheData|ResetMissionCacheData]]
| [[Lua接口/服务端/ResetMissionCacheData|ResetMissionCacheData]]
| style="padding:8px;vertical-align:top;overflow-wrap:anywhere;" | <code style="white-space:normal;overflow-wrap:anywhere;">sceneId, selfId</code>;清空缓存;部分分支无返回值。
| <code>sceneId, selfId</code>;清空缓存;部分分支无返回值。
|}
|}
临时缓存在玩家当前会话期间有效,切换场景或重新登录后重置。[[Lua接口/服务端/GetMissionCacheData|GetMissionCacheData]] 和 [[Lua接口/服务端/SetMissionCacheData|SetMissionCacheData]] 部分分支不返回值,接收可能得到 nil。
临时缓存在玩家当前会话期间有效,切换场景或重新登录后重置。[[Lua接口/服务端/GetMissionCacheData|GetMissionCacheData]] 和 [[Lua接口/服务端/SetMissionCacheData|SetMissionCacheData]] 部分分支不返回值,接收可能得到 nil。


== 标志位 ==
== 标志位 ==
{| class="wikitable" style="width:100%;table-layout:fixed;border-collapse:collapse;font-size:13px;"
{| class="wikitable"
! scope="col" style="text-align:left;background:#edf3f2;padding:8px;" | 接口
! scope="col" | 接口
! scope="col" style="text-align:left;background:#edf3f2;padding:8px;" | 参数与返回
! scope="col" | 参数与返回
|-
|-
| style="padding:8px;vertical-align:top;overflow-wrap:anywhere;" | [[Lua接口/服务端/GetMissionFlag|GetMissionFlag]]
| [[Lua接口/服务端/GetMissionFlag|GetMissionFlag]]
| style="padding:8px;vertical-align:top;overflow-wrap:anywhere;" | <code style="white-space:normal;overflow-wrap:anywhere;">sceneId, selfId, bitIndex</code> → 标志位(0 或 1);非玩家返回 0。
| <code>sceneId, selfId, bitIndex</code> → 标志位(0 或 1);非玩家返回 0。
|-
|-
| style="padding:8px;vertical-align:top;overflow-wrap:anywhere;" | [[Lua接口/服务端/SetMissionFlag|SetMissionFlag]]
| [[Lua接口/服务端/SetMissionFlag|SetMissionFlag]]
| style="padding:8px;vertical-align:top;overflow-wrap:anywhere;" | <code style="white-space:normal;overflow-wrap:anywhere;">sceneId, selfId, bitIndex, value</code>;无返回值。
| <code>sceneId, selfId, bitIndex, value</code>;无返回值。
|}
|}
标志位是按 bitIndex 索引的二进制位,用于记录任务进度或状态开关。[[Lua接口/服务端/GetMissionFlag|GetMissionFlag]] 非玩家对象返回 0,[[Lua接口/服务端/SetMissionFlag|SetMissionFlag]] 无返回值。
标志位是按 bitIndex 索引的二进制位,用于记录任务进度或状态开关。[[Lua接口/服务端/GetMissionFlag|GetMissionFlag]] 非玩家对象返回 0,[[Lua接口/服务端/SetMissionFlag|SetMissionFlag]] 无返回值。


== 读取任务参数 ==
== 读取任务参数 ==
<pre style="white-space:pre-wrap;overflow-wrap:anywhere;font-size:13px;line-height:1.7;padding:12px;background:#f5f7f8;border:1px solid #dbe3e6;">local val = GetMissionParam(sceneId, selfId, misIndex, paramIndex)
<pre>local val = GetMissionParam(sceneId, selfId, misIndex, paramIndex)
if type(val) == "number" and val ~= -1 then
if type(val) == "number" and val ~= -1 then
     -- 取得任务参数值
     -- 取得任务参数值
第74行: 第74行:


== 写入任务参数 ==
== 写入任务参数 ==
<pre style="white-space:pre-wrap;overflow-wrap:anywhere;font-size:13px;line-height:1.7;padding:12px;background:#f5f7f8;border:1px solid #dbe3e6;">SetMissionByIndex(sceneId, selfId, misIndex, paramIndex, 1)
<pre>SetMissionByIndex(sceneId, selfId, misIndex, paramIndex, 1)
-- 无返回值;不能写 if SetMissionByIndex(...) then
-- 无返回值;不能写 if SetMissionByIndex(...) then
-- 想确认应改读 GetMissionParam 回比</pre>
-- 想确认应改读 GetMissionParam 回比</pre>
第113行: 第113行:
[[Lua接口/函数不存在|函数不存在或提示 nil]] · [[Lua接口/参数类型与顺序|参数类型与顺序]] · [[Lua接口/返回值判断|返回值判断]] · [[Lua接口/对象ID与GUID|对象 ID 与 GUID]]
[[Lua接口/函数不存在|函数不存在或提示 nil]] · [[Lua接口/参数类型与顺序|参数类型与顺序]] · [[Lua接口/返回值判断|返回值判断]] · [[Lua接口/对象ID与GUID|对象 ID 与 GUID]]


<div style="margin-top:20px;padding-top:10px;border-top:1px solid #dbe3e6;color:#657078;font-size:12px;">本页函数签名与返回约定依据当前服务端注册表整理;sceneId、selfId 由实际回调提供,业务枚举、属性类型编号与运行效果需要实测。</div>
<div class="lua-note">本页函数签名与返回约定依据当前服务端注册表整理;sceneId、selfId 由实际回调提供,业务枚举、属性类型编号与运行效果需要实测。</div>


</div>
</div>

2026年9月19日 (六) 16:59的版本

首页 · 服务端接口 · 调用约定

读写任务参数、全局数据块、临时缓存与标志位。任务参数按索引读写,部分接口支持字节级修改。

任务参数

接口 参数与返回
GetMissionParam sceneId, selfId, misIndex, paramIndex → 参数值;0 或 -1 表示未设置或失败。
SetMissionByIndex sceneId, selfId, misIndex, paramIndex, value;无返回值。
GetMissionParamEx sceneId, selfId, missionIndex, paramIndex, byteIndex → 字节值;0 或 -1。
SetMissionParamByIndexEx sceneId, selfId, missionIndex, paramIndex, byteIndex, value;无返回值。

GetMissionParam 按任务索引和参数索引读取整数值;GetMissionParamEx 进一步按字节索引读取参数中的指定字节。SetMissionByIndex、SetMissionParamByIndexEx 都无返回值。

全局数据块

接口 参数与返回
GetMissionData sceneId, selfId, nIndex → 数据值;失败 -1。
SetMissionData sceneId, selfId, nIndex, nData;无返回值。

全局数据块是跨任务共享的玩家数据,按 nIndex 索引读写。SetMissionData 无返回值。

临时缓存

接口 参数与返回
GetMissionCacheData sceneId, selfId, nIndex → 缓存值;部分分支无返回值。
SetMissionCacheData sceneId, selfId, nIndex, nData;部分分支无返回值。
ResetMissionCacheData sceneId, selfId;清空缓存;部分分支无返回值。

临时缓存在玩家当前会话期间有效,切换场景或重新登录后重置。GetMissionCacheData 和 SetMissionCacheData 部分分支不返回值,接收可能得到 nil。

标志位

接口 参数与返回
GetMissionFlag sceneId, selfId, bitIndex → 标志位(0 或 1);非玩家返回 0。
SetMissionFlag sceneId, selfId, bitIndex, value;无返回值。

标志位是按 bitIndex 索引的二进制位,用于记录任务进度或状态开关。GetMissionFlag 非玩家对象返回 0,SetMissionFlag 无返回值。

读取任务参数

local val = GetMissionParam(sceneId, selfId, misIndex, paramIndex)
if type(val) == "number" and val ~= -1 then
    -- 取得任务参数值
end

GetMissionParam 未设置返回 0、失败返回 -1。先判类型再排除 -1。

写入任务参数

SetMissionByIndex(sceneId, selfId, misIndex, paramIndex, 1)
-- 无返回值;不能写 if SetMissionByIndex(...) then
-- 想确认应改读 GetMissionParam 回比

SetMissionByIndex 无返回值。需要确认参数是否写入成功,应在设置后用 GetMissionParam 读回比较。

相关主题

服务端调用约定 · 服务端调用示例 · 服务端函数索引

函数不存在或提示 nil · 参数类型与顺序 · 返回值判断 · 对象 ID 与 GUID

本页函数签名与返回约定依据当前服务端注册表整理;sceneId、selfId 由实际回调提供,业务枚举、属性类型编号与运行效果需要实测。