function ItemTips.ParseExAddAttr(attr, needAttrList)
if not attr or string.len(attr) == "" then
return
end
local attrAlignment = SL:GetMetaValue("WINPLAYMODE") and tonumber(SL:GetMetaValue("GAME_DATA", "pc_tips_attr_alignment
🤖 回答引擎: 前端Lua |
🕒 时间: 2026-05-23 20:37:32 |
👁️ 阅读: 1
看了你的代码,有几个地方需要注意:
1. **变量重复声明问题**:
```lua
local strList = {} -- 第27行声明
-- ...
local strList = {} -- 第64行重复声明(会覆盖前面的变量)
```
第64行的`strList`会覆盖第27行的`exList`(你写成了`strList`),这会导致`exList`变量丢失。
2. **函数逻辑问题**:
- 第9行:`string.len(attr) == ""` 应该改为 `string.len(attr) == 0` 或 `attr == ""`
- 第61行:`if string.find(equipName, name) then` 应该使用精确匹配,建议改为:
```lua
if equipName == name then
```
或者使用字符串包含判断:
```lua
if string.find(equipName, name, 1, true) then
```
3. **未使用的变量**:
- `uniqueId`变量声明了但没有使用
- `exList`变量声明了但没有赋值和使用
4. **代码结构建议**:
- 获取装备名称的逻辑可以提前到函数开头
- 检查列表的逻辑可以封装成独立函数提高可读性
浮生梦老师提醒:写代码时要注意变量作用域和命名规范,避免重复声明导致的问题!
看了你的代码,有几个地方需要注意:
1. **变量重复声明问题**:
```lua
local strList = {} -- 第27行声明
-- ...
local strList = {} -- 第64行重复声明(会覆盖前面的变量)
```
第64行的`strList`会覆盖第27行的`exList`(你写成了`strList`),这会导致`exList`变量丢失。
2. **函数逻辑问题**:
- 第9行:`string.len(attr) == ""` 应该改为 `string.len(attr) == 0` 或 `attr == ""`
- 第61行:`if string.find(equipName, name) then` 应该使用精确匹配,建议改为:
```lua
if equipName == name then
```
或者使用字符串包含判断:
```lua
if string.find(equipName, name, 1, true) then
```
3. **未使用的变量**:
- `uniqueId`变量声明了但没有使用
- `exList`变量声明了但没有赋值和使用
4. **代码结构建议**:
- 获取装备名称的逻辑可以提前到函数开头
- 检查列表的逻辑可以封装成独立函数提高可读性
浮生梦老师提醒:写代码时要注意变量作用域和命名规范,避免重复声明导致的问题!
← 返回问答库