{"id":14997867,"url":"https://github.com/joshalexjacobs/simplytimers","last_synced_at":"2025-10-29T16:43:13.942Z","repository":{"id":142022225,"uuid":"71487025","full_name":"Joshalexjacobs/SimplyTimers","owner":"Joshalexjacobs","description":"A simple timer library created for the Love2D framework","archived":false,"fork":false,"pushed_at":"2022-11-11T06:48:34.000Z","size":11,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-09T13:42:25.811Z","etag":null,"topics":["library","love-game-engine","love2d","love2d-framework","lua","timer"],"latest_commit_sha":null,"homepage":null,"language":"Lua","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Joshalexjacobs.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"ko_fi":"stumpheadgames"}},"created_at":"2016-10-20T17:24:44.000Z","updated_at":"2022-11-11T06:48:38.000Z","dependencies_parsed_at":"2023-07-07T08:01:16.775Z","dependency_job_id":null,"html_url":"https://github.com/Joshalexjacobs/SimplyTimers","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Joshalexjacobs/SimplyTimers","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Joshalexjacobs%2FSimplyTimers","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Joshalexjacobs%2FSimplyTimers/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Joshalexjacobs%2FSimplyTimers/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Joshalexjacobs%2FSimplyTimers/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Joshalexjacobs","download_url":"https://codeload.github.com/Joshalexjacobs/SimplyTimers/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Joshalexjacobs%2FSimplyTimers/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":272247350,"owners_count":24899544,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-26T02:00:07.904Z","response_time":60,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["library","love-game-engine","love2d","love2d-framework","lua","timer"],"created_at":"2024-09-24T17:32:53.948Z","updated_at":"2025-10-29T16:43:13.871Z","avatar_url":"https://github.com/Joshalexjacobs.png","language":"Lua","funding_links":["https://ko-fi.com/stumpheadgames"],"categories":[],"sub_categories":[],"readme":"# SimplyTimers.lua\n\nAn easy to use timer library created for the Love2D framework.\n\n## API\n\n### Require SimplyTimers\n\n``` lua\nrequire \"SimplyTimers\"\n```\n\n### Creating a new timer\n\n``` lua\naddTimer(time, name, timerList)\n```\n\nThe addTimer function asks for a time (in seconds), a name (string), and a timerList (a list of timers).\n\n#### Time\nTime is passed in seconds and NOT milliseconds, but will take fractions of a second.\n\n``` lua\n-- 500 milliseconds\naddTimer(0.5, name, timerList)\n\n-- 100 milliseconds\naddTimer(0.1, name, timerList)\n\n-- 2 seconds\naddTimer(2.0, name, timerList)\n```\n\n#### Name\nThe Name parameter is stored with the timer and acts as a label. Whenever you want to access that timer again you need to use it's name to call it.\n\n``` lua\n-- add a timer with the name \"shoot\"\naddTimer(0.7, \"shoot\", timerList)\n\n-- check if the shoot timer is finished\nif updateTimer(dt, \"shoot\", timerList) then\n  -- ...\nend\n```\n\n#### TimerList\nThe timerList is where your timers will be stored. There's no limit to how many different timerLists you may have and how many timers are in each list.\nThis means that each and every entity in our game can have their own timerList.\n\nThis way we don't have to update every single timer created every tick. We only have to update the timers that are currently being used by active entities.\n\n``` lua\nif entity.isDead and checkTimer(\"dead\", entity.timers) == false then\n  addTimer(0.6, \"dead\", entity.timers)\n  -- play death animation\nend\n```\n\n### Updating a timer\n\n``` lua\nupdateTimer(dt, name, timerList)\n```\n\nThe updateTimer function either returns TRUE or FALSE. If the return value is false, then the timer has yet to hit 0. If the return value is true, then the timer we're updating has just reached 0 and is complete.\n\n``` lua\nif updateTimer(dt, \"dead\", entity.timers) then\n  -- our death animation has finished\n  deleteTimer(\"dead\", entity.timers)\nend\n```\n\n### Deleting a timer\n\n``` lua\ndeleteTimer(name, timerList)\n```\n\nDeleting a timer only requires the timer's name and the list it's stored in. This removes the timer from the timerList which allows us to reuse it's name for a future timer.\n\n``` lua\ndeleteTimer(\"shoot\", entity.timers)\n```\n\n### Reseting a timer\n\n``` lua\nresetTimer(time, name, timerList)\n```\n\nReseting a timer is almost identical to adding a timer.\n\n``` lua\nresetTimer(0.2, \"shoot\", entity.timers)\n```\n\n### Get a timer's time\n\n``` lua\ngetTime(name, timerList)\n```\n\nIf needed, you can access a timer's current time. The return value will be in seconds.\n\n``` lua\ngetTime(\"follow\", entity.timers)\n```\n\n### Check if a timer exists\n\n``` lua\ncheckTimer(name, timerList)\n```\n\nIf you need to check whether a timer exists in the given timerList you can us the checkTimer function.\n\n``` lua\nif checkTimer(\"chase\", entity.timers) == false then\n  addTimer(1.5, \"chase\", entity.timers)\nend\n```\n\n## Examples\n### Some examples of where SimplyTimers.lua can be used:\n\n####The main.lua file in this git repo:\n``` lua\nrequire \"SimplyTimers\"\n\nlocal index = 1\nlocal remaining = 0.0\nlocal max = 0\nlocal timers = {}\n\nfunction love:keypressed(key, code)\n  if checkTimer(\"start\", timers) == false then\n    if key == \"space\" or key == \"return\" then\n      addTimer(remaining, \"start\", timers)\n      max = remaining\n    end\n  end\n\n  if key == \"escape\" then\n    love.event.quit()\n  end\n\n  if checkTimer(\"start\", timers) == false and remaining \u003c 10 then\n    if key == \"1\" then\n      remaining = remaining * 10 + 0.01\n    elseif key == \"2\" then\n      remaining = remaining * 10 + 0.02\n    elseif key == \"3\" then\n      remaining = remaining * 10 + 0.03\n    elseif key == \"4\" then\n      remaining = remaining * 10 + 0.04\n    elseif key == \"5\" then\n      remaining = remaining * 10 + 0.05\n    elseif key == \"6\" then\n      remaining = remaining * 10 + 0.06\n    elseif key == \"7\" then\n      remaining = remaining * 10 + 0.07\n    elseif key == \"8\" then\n      remaining = remaining * 10 + 0.08\n    elseif key == \"9\" then\n      remaining = remaining * 10 + 0.09\n    elseif key == \"0\" then\n      remaining = remaining * 10 + 0.00\n    end\n  end\nend\n\nfunction love.load(arg)\n  smallestFont = love.graphics.newFont(\"kenpixel_mini.ttf\", 15)\n  smallFont = love.graphics.newFont(\"kenpixel_mini.ttf\", 20)\n  bigFont = love.graphics.newFont(\"kenpixel_mini.ttf\", 40)\n  love.graphics.setFont(bigFont)\nend\n\nfunction love.update(dt)\n  if updateTimer(dt, \"start\", timers) then\n    deleteTimer(\"start\", timers)\n    remaining = 0\n  end\nend\n\nfunction love.draw()\n  love.graphics.printf(\"Simply Timers\", 0, 50, 800, \"center\")\n  love.graphics.printf( string.format(\"%.2f\", tostring(remaining)), 350, 150, 500 )\n\n  if checkTimer(\"start\", timers) then\n    love.graphics.printf(\"Timer Active\", 0, 400, 800, \"center\")\n    love.graphics.setColor(100, 0, 0, 255)\n    love.graphics.rectangle(\"fill\", 106, 206, remaining/max * 587, 19)\n    love.graphics.setColor(255, 255, 255, 255)\n    remaining = getTime(\"start\", timers)\n  else\n    love.graphics.printf(\"Timer Inactive\", 0, 400, 800, \"center\")\n  end\n\n  love.graphics.setFont(smallFont)\n  love.graphics.printf(string.format(\"%.2f\" , tostring(max)), 640, 180, 200)\n  love.graphics.setFont(smallestFont)\n  love.graphics.printf(\"Use 0-9 to set the timer\\nPress Space/Enter to start\", 5, 5, 800, \"left\")\n  love.graphics.setFont(bigFont)\n\n  love.graphics.rectangle(\"line\", 106, 206, 587, 19)\nend\n```\n\n####An enemy update function:\n``` lua\nbehaviour = function(dt, entity, world)\n  if entity.isDead == false then\n    local angle = math.atan2(entity.y - player.y, entity.x - player.x)\n    entity.dx = -math.cos(angle) * dt * entity.speed\n    entity.dy = -math.sin(angle) * dt * entity.speed\n\n    if entity.hp \u003c= 0 then\n      entity.isDead = true\n    end\n\n  elseif entity.isDead and checkTimer(\"dead\", entity.timers) == false then\n    addTimer(0.6, \"dead\", entity.timers)\n    entity.explode:play()\n    entity.curAnim = 2\n  end\n\n  if updateTimer(dt, \"dead\", entity.timers) then\n    entity.playDead = true\n  end\nend,\n```\n\n####Part of an enemy bullets update function:\n``` lua\nfunction updateEBullets(dt, world)\n  for i, newEBullet in ipairs(eBullets) do\n    -- ...\n\n    if updateTimer(dt, \"life\", newEBullet.timers) then\n      newEBullet.isDead = true\n      if world:hasItem(newEBullet) then removeEBullet(newEBullet, i, world) end\n    end\n\n    if newEBullet.isDead == true then\n      if checkTimer(\"life\", newEBullet.timers) then\n        deleteTimer(\"life\", newEBullet.timers)\n      end\n\n      newEBullet.curAnim = 2\n      newEBullet.type = \"dead\"\n\n      if checkTimer(\"dead\", newEBullet.timers) == false then\n        addTimer(0.4, \"dead\", newEBullet.timers)\n      end\n\n      if updateTimer(dt, \"dead\", newEBullet.timers) then\n        newEBullet.playDead = true\n      end\n    end\n  end\nend\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoshalexjacobs%2Fsimplytimers","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjoshalexjacobs%2Fsimplytimers","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoshalexjacobs%2Fsimplytimers/lists"}