local attrDescs = GUIFunction:GetParseItemDesc(suitConfig.equipAttStr)
if attrDescs and attrDescs.desc and next(attrDescs.desc) then --这里不支持top bottom
string.gsub(attrDescs.desc[1].text, "250", "13")
string.gsub(attrDescs.desc[2].
string.gsub函数在Lua中不会修改原始字符串,而是返回替换后的新字符串。你需要将结果赋值回去才能生效。
你的代码应该这样修改:
```lua
local attrDescs = GUIFunction:GetParseItemDesc(suitConfig.equipAttStr)
if attrDescs and attrDescs.desc and next(attrDescs.desc) then
for i = 1, 5 do
if attrDescs.desc[i] and attrDescs.desc[i].text then
attrDescs.desc[i].text = string.gsub(attrDescs.desc[i].text, "250", "13")
attrDescs.desc[i].text = string.gsub(attrDescs.desc[i].text, "251", "13")
end
end
end
```
或者更简洁的方式:
```lua
local attrDescs = GUIFunction:GetParseItemDesc(suitConfig.equipAttStr)
if attrDescs and attrDescs.desc and next(attrDescs.desc) then
for i, desc in ipairs(attrDescs.desc) do
if i <= 5 and desc.text then
desc.text = string.gsub(desc.text, "250", "13")
desc.text = string.gsub(desc.text, "251", "13")
end
end
end
```
记住:string.gsub返回新字符串,原字符串不变。每次替换都要把结果存回去!