local zhuanpanOBJ = {}
zhuanpanOBJ.Name = "zhuanpanOBJ"
zhuanpanOBJ.cfg = {
{
{ showReward = { { 19, 12 } }, index2 = 1 },
{ showReward = { { 19, 18 } }, index2 = 2 },
{ showReward = { { 19, 20 } }, index2 = 3 },
🤖 回答引擎: 前端Lua |
🕒 时间: 2026-03-09 16:46:46 |
👁️ 阅读: 13
看了你的代码,有几个地方需要修正。主要问题是使用了知识库中不存在的函数,以及一些逻辑上的小问题。
```lua
-- 修正后的代码:
function zhuanpanOBJ:main(p1, p2, p3, data)
SL:print("p1, p2, p3", p1, p2, p3, data)
self.p1 = p1 or 1
-- 获取服务端数据
self.Data = SL:JsonDecode(SL:GetMetaValue("SERVER_VALUE", "HUMAN(幸运转盘数据)"))
-- 创建父节点(缺少这行代码)
local parent = GUI:Win_Create(self.Name, 0, 0, 0, 0, false, false, true, false)
self._parent = parent
-- 加载UI(缺少这行代码)
GUI:LoadExport(parent, "A/zhuanpanUI", function()
self.ui = GUI:ui_delegate(parent)
-- 这里添加你的其他初始化代码
self:createItemShow()
self:pullpay()
-- 显示抽奖次数
local countKey = tostring(self.p1)
local count = self.Data and self.Data[countKey] and self.Data[countKey].count or 0
GUI:Text_Create(parent, "Text_count_" .. self.p1, -230, -234, 20, "#ff00ff",
string.format("今日可抽奖:【%s/5】次", count))
end)
end
function zhuanpanOBJ:pullpay()
-- 根据p1获取对应的购买配置
local currentTab = self.tab[self.p1] or {}
for i = 1, #currentTab do
local dataKey = tostring(self.p1)
if self.Data and self.Data[dataKey] and (self.Data[dataKey].cishu < i or self.Data[dataKey].cishu <= 0) then
-- 修正:使用正确的按钮创建函数
local btn = GUI:Button_Create(self._parent, "btn_" .. i, 300, 132 - (i - 1) * 42, "res/public/1900000680.png")
GUI:Button_setTitleText(btn, currentTab[i].jg .. "元购买")
GUI:Button_setTitleColor(btn, "#FF00FF3C")
GUI:addOnClickEvent(btn, function()
SL:SendLuaNetMsg(1100, self.p1, 999, i, "购买")
end)
elseif self.Data and self.Data[dataKey] and self.Data[dataKey].cishu >= i then
local imgPath = "res/custom/common/zt/yz03.png"
GUI:Image_Create(self._parent, "Image_ygm_" .. i, 255, 112 - (i - 1) * 42, imgPath)
end
end
local dataKey = tostring(self.p1)
if self.Data and self.Data[dataKey] and self.Data[dataKey].all_pack ~= 1 then
-- 修正:使用正确的按钮创建函数
local btn_goumai = GUI:Button_Create(self._parent, "btn_goumai", 225, -160, "res/public/1900000680.png")
GUI:Button_setTitleText(btn_goumai, "一键购买")
GUI:Button_setTitleColor(btn_goumai, "#FF00FBFF")
GUI:addOnClickEvent(btn_goumai, function()
-- 注意:pullUpRecharge函数需要你自己定义
self:pullUpRecharge()
end)
else
local imgPath = "res/custom/common/zt/yz03.png"
GUI:Image_Create(self._parent, "Image_goumai_", 190, -180, imgPath)
end
-- 修正:使用正确的按钮创建函数
local btn_lingqu = GUI:Button_Create(self._parent, "btn_lingqu", 255, -220, "res/public/1900000680.png")
GUI:Button_setTitleText(btn_lingqu, "领取称号")
GUI:Button_setTitleColor(btn_lingqu, "#FF00FBFF")
GUI:addOnClickEvent(btn_lingqu, function()
SL:SendLuaNetMsg(1100, self.p1, 0, 2, "领取称号")
end)
end
-- 抽奖动画中的问题修正
function zhuanpanOBJ:lotteryAnim(gift_idx)
-- 为每个转盘单独记录old_idx
self.old_idx = self.old_idx or {}
self.old_idx[self.p1] = self.old_idx[self.p1] or gift_idx * 3
-- 修正:这里应该是self.ui.btn_lottery
if self.ui and self.ui.btn_lottery then
GUI:setEnabled(self.ui.btn_lottery, false)
end
-- ... 其他代码保持不变 ...
-- 修正:这里应该是self.ui.btn_lottery
if self.ui and self.ui.btn_lottery then
GUI:setEnabled(self.ui.btn_lottery, true)
end
end
```
**主要问题总结:**
1. **函数不存在**:`GUI:createButton` 和 `GUI:onClick` 在知识库中不存在
- 应该使用 `GUI:Button_Create` 创建按钮
- 使用 `GUI:addOnClickEvent` 添加点击事件
2. **缺少UI加载**:`main` 函数中缺少创建父节点和加载UI的代码
3. **按钮文本设置**:按钮创建后需要使用 `GUI:Button_setTitleText` 和 `GUI:Button_setTitleColor` 设置文本
4. **变量引用**:在 `lotteryAnim` 函数中,`zhuanpanOBJ.ui.btn_lottery` 应该改为 `self.ui.btn_lottery`
5. **自定义函数**:`pullUpRecharge` 函数需要你自己定义,因为知识库中没有这个函数
你的思路是对的,通过 `p1` 参数来区分不同的转盘,配置表也设计得很清晰。修正这些函数调用问题后,代码应该就能正常工作了。
← 返回问答库