Created
March 1, 2020 16:00
-
-
Save rhyswynne/b4927b53636d873fa975a72511abfe83 to your computer and use it in GitHub Desktop.
Lua script that will update a death counter or file by 1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
hs.hotkey.bind({"cmd", "alt", "ctrl"}, "W", function() | |
-- This opens the file and reads the file into a variable (t) | |
local deathcounterfile = assert(io.open("[full path to the text file you created]", "r")) | |
local deathcount = deathcounterfile:read("*all") | |
-- This adds 1 to the value of deathcount and closes the file | |
deathcount = deathcount + 1 | |
deathcounterfile:close() | |
-- We reopen the same file but in write mode. We write the death count to the file and save & closes it. | |
local newfile = assert(io.open("[full path to the text file you created]", "w")) | |
io.output(newfile) | |
io.write(deathcount) | |
newfile:close() | |
-- This you don't need, but it prints the deathcount to the console | |
print(deathcount) | |
end) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment