0

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

4

2 回答 2

0

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

尝试这个,

string.format("You%s need a %s", negation, tostring(clothwear or summerwear or innerwear or southerwear or outerwear))
于 2018-07-02T07:19:01.537 回答
0

temp大于Settings.Ss_Limit或 等于Settings.*_Limit、 所有summerwear、和中的任何一个innerwear时。这使得成为(布尔值)而不是导致错误的字符串。southerwearcoatwearfalse(summerwear or innerwear or southerwear or outerwear)false

可能的修复:

--[[ 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
于 2017-09-06T00:25:29.413 回答