编辑雨量表皮肤的lua文件“您需要外套吗”
获取此代码标题中的错误
--[[ Given the current temperature, return the appropriate
string for the main string meter ]]
local function getMainString( temp )
local negation = (temp > Settings.Ss_Limit) and " don't" or ""
local summerwear = (temp < Settings.Ss_Limit) and (temp > Settings.Vest_Limit) and "shirt and shorts"
local innerwear = (temp < Settings.Vest_Limit) and (temp > Settings.Jacket_Limit) and "vest"
local southerwear = (temp < Settings.Jacket_Limit) and (temp > Settings.Coat_Limit) and "jacket"
local outerwear = (temp < Settings.Coat_Limit) and "coat"
return string.format("You%s need a %s", negation, (summerwear or innerwear or southerwear or outerwear))
end
应该根据温度给正确的衣服。我曾尝试在不同的位置进行温度变化,而唯一的错误是温度超过Ss_limit。我没有太多的编码经验,所以请先谢谢
最佳答案
当temp
大于Settings.Ss_Limit
或等于Settings.*_Limit
中的任何一个时,所有summerwear
,innerwear
,southerwear
和coatwear
均为false
。这会使(summerwear or innerwear or southerwear or outerwear)
成为false
( bool(boolean) 值),而不是引起错误的字符串。
可能的解决方法:
--[[ Given the current temperature, return the appropriate
string for the main string meter ]]
local function getMainString( temp )
local negation = (temp > Settings.Ss_Limit) and " don't" or ""
--[[ this is used to produce "You don't need a cloth" when
temp is greater than Ss_Limit. Adjust the string based on your own need.
]]
local clothwear = (temp > Settings.Ss_Limit) and "cloth"
--[[ changed < to <=, the following is the same, as not to get an error
when temp equals any of the _Limit .
]]
local summerwear = (temp <= Settings.Ss_Limit) and (temp > Settings.Vest_Limit) and "shirt and shorts"
local innerwear = (temp <= Settings.Vest_Limit) and (temp > Settings.Jacket_Limit) and "vest"
local southerwear = (temp <= Settings.Jacket_Limit) and (temp > Settings.Coat_Limit) and "jacket"
local outerwear = (temp <= Settings.Coat_Limit) and "coat"
--[[ added clothwear here, to produce proper output
when temp is greater than Ss_Limit
]]
return string.format("You%s need a %s", negation, (clothwear or summerwear or innerwear or southerwear or outerwear))
end
关于string - 'format'的错误参数#3(预期字符串, bool 值)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46056455/