【发布时间】:2020-05-07 21:13:15
【问题描述】:
for amountofspinstodo = 1, 100 do
local pick = math.random( 1, #box.CONTENTS )
local rarity = INV:CalculateItemRarity()
local ITEMPICK = INV:GetDataFromName(box.CONTENTS[pick])
local RARITYS_OF_ITEM_PICK = ITEMPICK.RARITYS
if has_value(RARITYS_OF_ITEM_PICK, rarity)then
tbl.spintable[amountofspinstodo] = { NAME = box.CONTENTS[pick], RARITY = rarity }
print(amountofspinstodo)
else
amountofspinstodo = amountofspinstodo - 1
print(amountofspinstodo)
end
end
我做了这个for循环来检查一个项目是否有一定的稀有度,如果有,那么就允许它成为一个项目,但如果它没有稀有度,那么它应该让for循环做到这一点再一次,直到每个项目都被挑选出来。但是,当我运行 for 循环时,它会这样做,我不知道为什么。
有些数字是重复的,例如 48 和 48,应该是 48 和 49。
任何帮助将不胜感激!
-谢谢 D12
【问题讨论】:
-
嗨,欢迎来到 Stack Overflow!从技术上讲,您的代码正在执行您告诉它执行的操作,如果稀有度不匹配,则从
amountofspins中减去 1。但如果amountofspins与表中的项目数匹配,则最好使用print(#tbl.spintable)。此外,我认为您可能会考虑table.insert(tbl.spintable, {...}),而不是您现在的做法。 -
看起来您在发布的代码中错过了 for 循环的开头,您可以将其包括在内吗?
-
@Nifim 很抱歉,我现在已经添加了。
-
您不能从 for 循环中更改循环迭代器的值,您需要改用 while 循环
标签: lua