Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local forMsgFile = fs.open("for","r")
- local forMsg = forMsgFile.readAll()
- forMsgFile.close()
- local agnMsgFile = fs.open("against","r")
- local agnMsg = agnMsgFile.readAll()
- agnMsgFile.close()
- local moniter = peripheral.wrap("top")
- local votes = { forVotes = 0 , agnVotes = 0 }
- function screen(cv,msg)
- moniter.clear()
- moniter.setCursorPos(1,1)
- moniter.setTextColor(32)
- if cv then
- moniter.setBackgroundColor(2048)
- else
- moniter.setBackgroundColor(32768)
- end
- moniter.write(forMsg)
- moniter.setBackgroundColor(32768)
- if msg ~= nil then
- moniter.setCursorPos(1,3)
- moniter.setTextColor(1)
- moniter.write(msg)
- moniter.setBackgroundColor(32768)
- end
- moniter.setCursorPos(1,5)
- moniter.setTextColor(16384)
- if not cv then
- moniter.setBackgroundColor(2048)
- else
- moniter.setBackgroundColor(32768)
- end
- moniter.write(agnMsg)
- moniter.setBackgroundColor(32768)
- end
- if fs.exists("voteFile") == true then
- local vf = fs.open("voteFile","r")
- votes = textutils.unserialize(vf.readAll())
- end
- screen(true)
- while true do
- local currentVote = not rs.getInput("left")
- local confirmation = false
- screen(currentVote)
- local event = { os.pullEventRaw() }
- print( event[1].." "..event[2])
- if event[1] == "redstone" then
- confirmation = false
- currentVote = not rs.getInput("left")
- end
- if event[1] == "player" then
- if v[event[2]] == nil and not confirmation then
- screen(currentVote,event[2].." would you like to vote ".. (currentVote and "for" or "against").. "?")
- confirmation = true
- elseif v[event[2]] == nil and confirmation then
- confirmation = false
- v[event[2]] = currentVote
- save()
- screen(currentVote,"Thank you for voting.")
- end
- end
- end
- function save()
- local s = fs.open("voteFile","w")
- s.write(textutils.serialize(v))
- s.close()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement