local function networkCB(msgID, msgData)
local parent = GUI:Attach_RightTop()
local ui = GUI:ui_delegate(parent)
local tag = GUI:getTag(ui['bt_11'])
SL:print(tag)
if tag == -1 then
GUI:setTag(ui['bt_11'],1)
G
我仔细看了你的代码,发现了一个逻辑问题。你的代码结构是这样的:
```lua
if tag == -1 then
-- 执行一些操作
return -- 这里直接返回了
end
if tag == 1 then
-- 执行另一些操作
return
end
```
问题在于:当 `tag == -1` 时,执行完第一个 `if` 块后,代码遇到了 `return` 语句,直接结束了函数执行,所以永远不会走到下面的 `if tag == 1` 的判断。
**解决方案:**
把两个 `if` 语句改成 `if-elseif` 结构,或者使用 `else`:
```lua
if tag == -1 then
-- 执行一些操作
elseif tag == 1 then
-- 执行另一些操作
end
```
或者:
```lua
if tag == -1 then
-- 执行一些操作
else
-- 执行另一些操作
end
```
**修改后的代码:**
```lua
local function networkCB(msgID, msgData)
local parent = GUI:Attach_RightTop()
local ui = GUI:ui_delegate(parent)
local tag = GUI:getTag(ui['bt_11'])
SL:print("当前tag值:", tag)
if tag == -1 then
GUI:setTag(ui['bt_11'], 1)
GUI:addOnClickEvent(ui['bt_11'], function()
for i = 1, 10 do
GUI:setOpacity(ui['bt_'..i], 255)
local fadeOutAction = GUI:ActionFadeTo(0.5, 0)
local hideFunc = GUI:CallFunc(function()
GUI:setVisible(ui['bt_'..i], false)
end)
GUI:runAction(ui['bt_'..i], GUI:ActionSequence(fadeOutAction, hideFunc))
end
end)
elseif tag == 1 then
GUI:setTag(ui['bt_11'], -1)
-- zhankai(ui) -- 这里可以调用你的展开函数
end
end
SL:RegisterNetMsg(1000, networkCB)
```
这样修改后,当 `tag == -1` 时,会执行第一个逻辑;当 `tag == 1` 时,会执行第二个逻辑。代码就不会因为 `return` 而提前结束了。
另外,我还添加了一个 `SL:print("当前tag值:", tag)` 来帮助你调试,可以看到每次网络回调时 `tag` 的实际值。