I have no idea why this is. Anyone?
Oh, and please feel free to criticize the way I've gone about coding this. I'm as equally new to lua as I am löve and am generally a rubbish programmer
Thanks
(Change [start 10.0] to a lower number to see it working correctly).
Code: Select all
function love.load()
-- some text to try...
text = "Sample text [start 2.0]string 1[end 4.5] this should not be visible [start 5.0]string 2 [end 7.0]more ignored text [start 10.0]string 3.[end 12.5]"
audioSource = love.audio.newSource("audioFile.mp3")
love.audio.play(audioSource)
playing = true
--break up the text in the file and inset into categorised table arrays.
startsArray = {}
endsArray = {}
wordsArray = {}
for starts, words, ends in text:gmatch("%[start%s([%d%.]+)%](.-)%[end%s([%d%.]+)%]") do
table.insert(startsArray, starts)
table.insert(endsArray, ends)
table.insert(wordsArray, words)
end
index = 1 -- this is the start of the table array and a base for incrementation.
textCall = "Easy Video Language"
font = love.graphics.newFont(75)
love.graphics.setFont(font)
end
--
function love.keypressed(key)
if key == "escape" then
love.event.push("quit")
end
end
--
function love.update(dt)
position = audioSource:tell( "seconds" )
if index < 4 then
if string.format("%f", position) > startsArray[index] then
textCall = tostring(wordsArray[index])
print(startsArray[index] .. " | " .. wordsArray[index] .. " | " .. string.format("%f", position) )
index = index + 1
end
end
end
--
function love.draw()
love.graphics.printf(textCall, 10, 75, 800, 'center') -- Default title -- set in love.load()
love.graphics.printf(position, 10, 0, 800, 'center') -- check text is arriving on time.
end