2017-09-05 2 views
0

Modification d'un fichier lua pour la peau Rainmeter « Avez-vous besoin d'une veste » obtenir l'erreur dans le titre de ce codemauvais argument # 3 à 'format' (chaîne attendue, got 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 "" 
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 

Il est censé donner les vêtements correct en fonction Température. J'ai essayé avec différents endroits pour la variation de température, et la seule fois que j'obtiens l'erreur est quand la température est sur Ss_limit. Je n'ai pas beaucoup d'expérience de codage pour vous remercier à l'avance

+0

Cette ligne 'vêtements de plein air locale = (temp Settings.*_Limit, tous summerwear, innerwear, southerwear et coatwear sera false. Cela fait (summerwear or innerwear or southerwear or outerwear) être false (un booléen) au lieu d'une chaîne qui provoque l'erreur.

solution possible:

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