However I'm running into a problem.
The computer just reboots.
Are there any way of capturing the last action the computer does before shutting down - and perhaps saving that into a file?
If you'd like to help me out, here's my code:
(and sorry if it's a mess, but I'm no pro ;)/>)
Spoiler
-- Placement of monitor.
-- top/bottom/left/right/front/back
local monitorSide = "top"
local rHighS = "left" -- redstone input for Higher guess.
local rLowS = "right" -- redstone input for Lower guess.
local rOKS = "bottom" -- redstone input for OK button.
local maxTries = 100 -- Max Tries 0=infinite.
local difficulty = "easy" -- easy/medium/hard
---------------------------------
-- DO NOT EDIT BELOW THIS LINE --
---------------------------------
-- Initial variables
local mon = peripheral.wrap(monitorSide)
local version = "1.0"
local number = 0
local win = false
local tries = 0
local guess = 1
-- Slowprint for monitor (18 char MAX)
function monitorsp(text,monitor)
for x = 1, string.len(text) do
char = string.sub(text,x,x)
monitor.write(char)
sleep(0.1)
end
end
-- Faster to type moncur.
function moncur(x,y)
mon.setCursorPos(x,y)
end
-- Raise Guess
function raiseG()
if guess < 101 then
guess = guess + 1
moncur(1,7)
mon.clearLine()
mon.write("Guess: "..guess)
end
end
-- Lower Guess
function lowerG()
if guess > 0 then
guess = guess - 1
moncur(1,7)
mon.clearLine()
mon.write("Guess: "..guess)
end
end
-- Set difficulty settings
if difficulty == "easy" then
number = math.random(1,100)
elseif difficulty == "medium" then
number = math.random(1,250)
elseif difficulty == "hard" then
number = math.random(1,500)
else
number = math.random(1,100)
end
-- Display
do
mon.clear()
moncur(1,1)
mon.write("------------------")
moncur(1,2)
monitorsp("Welcome to HighLow",mon)
moncur(1,3)
mon.write("------------------")
moncur(1,4)
mon.write("Difficulty: "..difficulty)
moncur(1,5)
mon.write("Max Tries: "..maxTries)
moncur(1,6)
mon.write("------------------")
sleep(3)
moncur(1,2)
mon.clearLine()
moncur(1,2)
mon.write("Tries: "..tries)
moncur(1,7)
mon.write("Guess: "..guess)
end
-- Start the game
while true do
if tries > maxTries then
break
else
local event, param1 = os.pullEvent("redstone") -- Make sure the redstone only triggers once
if event == "redstone" and redstone.getInput(rHighS) == true then
raiseG()
elseif event == "redstone" and redstone.getInput(rLowS) == true then
lowerG()
elseif event == "redstone" and redstone.getInput(rOKS) == true then
tries = tries + 1
moncur(1,2)
mon.clearLine()
mon.write("Tries: "..tries)
if guess == number then
win = true
break
else
if guess < number then
moncur(1,8)
mon.clearLine()
mon.write("Too Low!")
else
moncur(1,8)
mon.clearLine()
mon.write("Too High!")
end
end
end
end
sleep(0)
end
-- Outro
do
mon.clear()
moncur(1,4)
mon.write("------------------")
moncur(1,5)
mon.write("- -")
moncur(1,6)
mon.write("- GAME OVER -")
moncur(1,7)
mon.write("- -")
moncur(1,8)
mon.write("------------------")
moncur(1,6)
if win == true then
monitorsp("- YOU WIN -",mon)
else
monitorsp("- YOU LOSE -",mon)
end
moncur(1,10)
monitorsp(("Tries: "..tries),mon)
end
Thanks in advance to anyone trying to help me out..
Edit:
Changed the codeblock to match my current code.
TheOriginalBIT solved my first problem - by adding a sleep(1) my program is now working.
with sleep(0), 1 redstone button equals 20 points instead of 1.
with sleep(1), 1 redstone button equals 1 point - but is VERY slow to increment/decrement.
– Using os.pullEvent("redstone") solves this issue.
- Now working on a toggle switch to be able to use a lever for fast increment/decrement.