Possibly useful code snippets
Posted: Sun Jun 01, 2014 1:14 am
While writing games I often come across some cool things that you can do with Lua, so I figured why not post them here.
If anyone else wants to join in feel free to, but as a legal warning I would just like to state that all code I post in this thread will be under the Whatever the Fuck you please Permissive License (sorry for the vulgarity). Anyone posting in this thread should also include a, small, permissive license, too.
This counts how many times WAIT() appears on your main.lua, so it will break if you use a call to it that doesn't exist in plain text on your main.lua. Besides that it works great.
If anyone else wants to join in feel free to, but as a legal warning I would just like to state that all code I post in this thread will be under the Whatever the Fuck you please Permissive License (sorry for the vulgarity). Anyone posting in this thread should also include a, small, permissive license, too.
Code: Select all
local WAIT = coroutine.wrap(function(f, returnvar)
local starttime = {}
local duration = {}
local counter = 0
local timecheck = false
local wordcount = 0
for i in love.filesystem.lines("main.lua") do
if string.find(i, "WAIT%b()") then
wordcount = wordcount + 1
end
end
while #starttime < wordcount do
local time = coroutine.yield()
starttime[#starttime + 1] = love.timer.getTime()
duration[#duration + 1] = time
end
while true do
timecheck = false
if love.timer.getTime() >= starttime[#starttime - counter] + duration[#duration - counter] then
starttime[#starttime - counter] = love.timer.getTime()
timecheck = returnvar or true
end
counter = counter + 1
if counter >= #starttime then
counter = 0
end
coroutine.yield(timecheck)
end
end)