错误的参数#3到'格式'(字符串预期,得到布尔值)?

时间:2017-09-05 13:39:31

标签: string error-handling lua rainmeter

编辑雨量计皮肤的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。我没有太多的编码经验,所以提前谢谢你

2 个答案:

答案 0 :(得分:0)

temp大于Settings.Ss_Limit或等于Settings.*_Limit中的任何一个时,summerwearinnerwearsoutherwear和{{ 1}}将是coatwear。这使false成为(summerwear or innerwear or southerwear or outerwear)(布尔值)而不是导致错误的字符串。

可能的解决方法:

false

答案 1 :(得分:0)

您需要手动将布尔类型评估为字符串。

尝试一下,

string.format("You%s need a %s", negation, tostring(clothwear or summerwear or innerwear or southerwear or outerwear))