Difference between revisions of "Module:IconBar"

From Minetest Wiki
Jump to navigation Jump to search
(Add Lua implementation of the Heart template)
 
m
Line 3: Line 3:
 
function p.hearts(num)
 
function p.hearts(num)
 
     num = num or 1
 
     num = num or 1
 +
    if num == 0 then
 +
        return "[[File:Empty heart.png|16px]]"
 +
    end
 
     local numFloor = math.floor(num)
 
     local numFloor = math.floor(num)
 
     local s = ""
 
     local s = ""
 
     for i = 1, numFloor do
 
     for i = 1, numFloor do
         s = s .. "[[File:Heart.png | 16px]]"
+
         s = s .. "[[File:Heart.png|16px]]"
 
     end
 
     end
 
     if numFloor ~= num then
 
     if numFloor ~= num then
         s = s .. "[[File:Half_heart.png | 16px]]"
+
         s = s .. "[[File:Half heart.png|16px]]"
 
     end
 
     end
 
     return s
 
     return s

Revision as of 14:42, 8 April 2017

local p = {}

function p.hearts(num)

   num = num or 1
   if num == 0 then
       return "Empty heart.png"
   end
   local numFloor = math.floor(num)
   local s = ""
   for i = 1, numFloor do
       s = s .. "Heart.png"
   end
   if numFloor ~= num then
       s = s .. "Half heart.png"
   end
   return s

end

return p