GUI, countdown with progress bar
Posted: Fri Feb 19, 2021 9:34 pm
Hi!
I've made small example for timer with countdown and GUI.
I've made small example for timer with countdown and GUI.
Code: Select all
line.button.text = math.floor (time+0.5) .. ' s'
Code: Select all
function create_line(y, time)
return { -- line
area = get_area{x=10, y=y, h=40, sw=10},
button =
{
area=get_area{x=10, y=y, h=40, w=200, s=2},
text="timer "..time.." s",
default_text="timer "..time.." s",
progress = 0
},
result =
{
area=get_area{x=210, y=y, h=40, sw=10, s=2},
text=0,
},
start = 0,
enabled = false,
timer = time -- seconds
}
end
Code: Select all
function load_table(name)
local chunk, errormsg = love.filesystem.load( name..'.lua' )
if not (errormsg) then
return chunk()
else
print('errormsg: '..errormsg)
end
end
Code: Select all
function savetable(tabl, name)
love.filesystem.write(name..".lua", 'return '.. serialize(tabl))
end
Code: Select all
serialize = function (tabl, indent)
indent = indent and indent .. ' ' or ' '
local str = indent..'{'
local bool = true
for i, v in pairs (tabl) do
local pr = (type(i)=="string") and i..'=' or ''
if type (v) == "table" then
str=str..string.char(10) -- new line before table
str = str..pr..serialize(v, indent)..','..string.char(10)
bool = true
elseif type (v) == "string" then
str = str..pr..'"'..tostring(v)..'"'..','
bool = false
else
str = str..pr..tostring(v)..','
bool = false
end
end
if bool then
str = str:sub(1, -3) -- remove last comma and char10
else
str = str:sub(1, -2) -- remove last comma
end
str=str..'}'
return str
end