前端
YuanShenChuQiao = {}
function YuanShenChuQiao:init()
self._cfg = Util:requireCfg(self.mCfg.clientObjPath)
end
function YuanShenChuQiao:main(npcData)
self.npcData = npcData or {}
self.npcID = self.npcData.npcID or 99999
self:sync
🤖 回答引擎: 前端Lua |
🕒 时间: 2026-04-17 16:59:20 |
👁️ 阅读: 5
你的问题是界面关闭后重新打开,进度条会从头开始。这是因为每次打开界面时,`data` 参数没有正确传递当前进度。
**问题分析:**
1. 前端 `YuanShenChuQiao:main(npcData)` 被调用时,会触发 `self:syncData(true)`
2. 后端 `syncData` 会调用 `self:initUI(actor)`,但这里没有传递当前的进度值
3. 所以前端 `updateUI` 中的 `index` 参数是 `nil`,导致进度条从0开始
**解决方案:**
需要在后端 `syncData` 中获取当前进度值,并传递给前端。
**后端修改:**
```lua
function YuanShenChuQiao:syncData(actor, showUI)
-- 获取当前进度(这里假设进度存储在玩家变量中)
local currentLevel = SL:GetMetaValue("YUANSHEN_LEVEL", actor) or 0
if showUI then
-- 将当前进度传递给前端
self:initUI(actor, currentLevel)
end
end
```
**前端修改:**
```lua
function YuanShenChuQiao:main(npcData)
self.npcData = npcData or {}
self.npcID = self.npcData.npcID or 99999
-- 这里需要后端传递当前进度值
self:syncData(true)
end
function YuanShenChuQiao:initUI(data)
UIManager:winCreate(self)
UIManager.widget_scale(self.parent, math.random(3), 0.15)
-- 更新UI数据,传入当前进度
self:updateUI(data)
end
```
**后端激活函数修改:**
```lua
function YuanShenChuQiao:JiHuo(actor,data)
local cfg = self._cfg[1]
local currentLevel = data.index or 0
local maxCount = 60
print(cfg.cost)
if GMLib:checkItems(actor, cfg.cost, 1, 1) then
GMLib:takes(actor, cfg.cost, self.cName)
currentLevel = currentLevel + 1
-- 保存进度到玩家变量
SL:SetMetaValue("YUANSHEN_LEVEL", actor, currentLevel)
if currentLevel > maxCount then
Msg.msg9(actor, "恭喜你满级了")
return
else
Msg.msg9(actor, "恭喜你激活第"..currentLevel.."级")
end
end
self:updateUI(actor,currentLevel)
end
```
**关键点:**
1. 后端需要存储玩家的进度值(使用 `SL:SetMetaValue`)
2. 打开界面时从后端获取当前进度
3. 每次激活后更新存储的进度值
这样关闭界面再打开时,就会显示正确的进度了。如果还有问题,记得检查浮生梦老师前端课程中的变量存储和传递方法!
你的问题是界面关闭后重新打开,进度条会从头开始。这是因为每次打开界面时,`data` 参数没有正确传递当前进度。
**问题分析:**
1. 前端 `YuanShenChuQiao:main(npcData)` 被调用时,会触发 `self:syncData(true)`
2. 后端 `syncData` 会调用 `self:initUI(actor)`,但这里没有传递当前的进度值
3. 所以前端 `updateUI` 中的 `index` 参数是 `nil`,导致进度条从0开始
**解决方案:**
需要在后端 `syncData` 中获取当前进度值,并传递给前端。
**后端修改:**
```lua
function YuanShenChuQiao:syncData(actor, showUI)
-- 获取当前进度(这里假设进度存储在玩家变量中)
local currentLevel = SL:GetMetaValue("YUANSHEN_LEVEL", actor) or 0
if showUI then
-- 将当前进度传递给前端
self:initUI(actor, currentLevel)
end
end
```
**前端修改:**
```lua
function YuanShenChuQiao:main(npcData)
self.npcData = npcData or {}
self.npcID = self.npcData.npcID or 99999
-- 这里需要后端传递当前进度值
self:syncData(true)
end
function YuanShenChuQiao:initUI(data)
UIManager:winCreate(self)
UIManager.widget_scale(self.parent, math.random(3), 0.15)
-- 更新UI数据,传入当前进度
self:updateUI(data)
end
```
**后端激活函数修改:**
```lua
function YuanShenChuQiao:JiHuo(actor,data)
local cfg = self._cfg[1]
local currentLevel = data.index or 0
local maxCount = 60
print(cfg.cost)
if GMLib:checkItems(actor, cfg.cost, 1, 1) then
GMLib:takes(actor, cfg.cost, self.cName)
currentLevel = currentLevel + 1
-- 保存进度到玩家变量
SL:SetMetaValue("YUANSHEN_LEVEL", actor, currentLevel)
if currentLevel > maxCount then
Msg.msg9(actor, "恭喜你满级了")
return
else
Msg.msg9(actor, "恭喜你激活第"..currentLevel.."级")
end
end
self:updateUI(actor,currentLevel)
end
```
**关键点:**
1. 后端需要存储玩家的进度值(使用 `SL:SetMetaValue`)
2. 打开界面时从后端获取当前进度
3. 每次激活后更新存储的进度值
这样关闭界面再打开时,就会显示正确的进度了。如果还有问题,记得检查浮生梦老师前端课程中的变量存储和传递方法!
← 返回问答库