feat: add clicker
This commit is contained in:
parent
6edb6edc17
commit
548c54e8b1
3 changed files with 49 additions and 0 deletions
10
README.md
10
README.md
|
@ -4,6 +4,16 @@ Just a bunch of computer craft scripts I guess?
|
|||
|
||||
If I write anything I'll put it here
|
||||
|
||||
## Scripts
|
||||
|
||||
### clicker
|
||||
|
||||
clicker.lua is a simple "cookie clicker like", funny number go up!
|
||||
|
||||
It gets a screen on the left of the computer (This is poorly writen but we ignore that~) and displays the number stored in `count.txt`, every 10 clicks it writes into that file with an updated count.
|
||||
|
||||
it reads `count.txt` every launch so the most progress you can lose is `9`.
|
||||
|
||||
## Mirrors
|
||||
|
||||
- Main: [https://git.aria.coffee/aria/computer-craft-scripts](https://git.aria.coffee/aria/computer-craft-scripts)
|
||||
|
|
38
clicker/clicker.lua
Normal file
38
clicker/clicker.lua
Normal file
|
@ -0,0 +1,38 @@
|
|||
m = peripheral.wrap("left")
|
||||
m.setTextScale(2)
|
||||
x = 0
|
||||
|
||||
file = io.input("count.txt")
|
||||
|
||||
|
||||
if file ~= nil then
|
||||
local file_contents = io.read()
|
||||
x = tonumber(file_contents)
|
||||
end
|
||||
|
||||
m.clear()
|
||||
|
||||
m.setCursorPos(1,1)
|
||||
m.write(x)
|
||||
|
||||
while true do
|
||||
local eventData = {os.pullEvent()}
|
||||
local event = eventData[1]
|
||||
local res = false
|
||||
|
||||
if event == "mouse_click" or event == "monitor_touch" then
|
||||
res = true
|
||||
elseif event == "redstone" then
|
||||
|
||||
res = redstone.getInput("front")
|
||||
end
|
||||
if res then
|
||||
x = x + 1
|
||||
m.setCursorPos(1,1)
|
||||
m.write(x)
|
||||
if x % 10 == 0 then
|
||||
io.output("count.txt")
|
||||
io.write(tostring(x))
|
||||
end
|
||||
end
|
||||
end
|
1
clicker/count.txt
Normal file
1
clicker/count.txt
Normal file
|
@ -0,0 +1 @@
|
|||
0
|
Loading…
Add table
Add a link
Reference in a new issue