在Watchmaker的Lua中修正图片透明度控制逻辑表达式问题
问题原因及修复方案
你的Lua表达式逻辑错误出在**or运算符的使用方式**上:
在Lua中,or是逻辑或运算符,它会返回第一个为"真"的操作数。你写的表达式里,"Friday Without Recycling"是非空字符串,在Lua中属于真值,所以不管"{ttrash}" == "Thursday Without Recycling"的结果是真还是假,整个or表达式都会返回真值(要么左边成立返回true,要么左边不成立返回"Friday Without Recycling")。之后and 100会直接返回100,永远触发不了or 0的分支。
修复后的表达式
方案1:完整的双条件比较
这是最直观的修正,给or两边都加上完整的相等判断:
("{ttrash}" == "Thursday Without Recycling" or "{ttrash}" == "Friday Without Recycling") and 100 or 0
方案2:用表集合判断(适合多值场景)
如果后续需要添加更多垃圾日,这种写法更易维护:
local target_days = { ["Thursday Without Recycling"] = true, ["Friday Without Recycling"] = true } target_days["{ttrash}"] and 100 or 0
补充说明
你单独判断单个值时功能正常,是因为单个判断的表达式是"{ttrash}" == "X" and 100 or 0:当不相等时,左边比较结果为false,false and 100返回false,最后false or 0返回0,逻辑是对的;但加上or "Y"后,Y作为真值破坏了整个逻辑链。
内容的提问来源于stack exchange,提问作者Ross
相关产品推荐
相关产品推荐

