0

Editing a lua file for the rainmeter skin "Do you need a jacket" getting the error in the title for this code


--[[ 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

It is supposed to give the correct clothing based on temperature. I have tried with different locations for temperature variation, and the only time i get the error is when the temperature is over Ss_limit. I dont have much coding experience so thank you in advance

Henriquez O.
  • 1
  • 1
  • 2
  • This line `local outerwear = (temp < Settings.Coat_Limit) and "coat"` may result in `false` when `temp == Settings.Coat_Limit`. Replace all `<` with `<=` to fix this error. – Egor Skriptunoff Sep 05 '17 at 14:09

2 Answers2

0

When temp is larger than Settings.Ss_Limit, or equals any of the Settings.*_Limit, all summerwear, innerwear, southerwearand coatwear will be false. This make (summerwear or innerwear or southerwear or outerwear) to be false (a boolean) instead of a string which is causing the error.

Possible fix:

--[[ 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
fefe
  • 3,342
  • 2
  • 23
  • 45
0

You need to manually evaluate boolean type to string.

Try this,

string.format("You%s need a %s", negation, tostring(clothwear or summerwear or innerwear or southerwear or outerwear))
WhatsThePoint
  • 3,395
  • 8
  • 31
  • 53
findux
  • 1
  • 3