Ran into another snag. I fixed most of it, but now if i tell it 1 coin and put one in it works, all code executes properly. if I tell it 2 coins and put one in, it turns on and gives me the 20 minute timer running the twentyTimer() function. if I say 3 and put in 2 coins it turns on and gives me 30 minute timer running the thirtyTimer() function. I've spent 1 hour trying to find out why and i'm super LOST. I cannot pastebin so here's the code.
Spoiler
term.clear()
term.setCursorPos(1,1)
local tenMin = 6
local twentyMin = 12
local thirtyMin = 18
local coinCount = 0 --coins inserted
function tenTimer() --starts 10 min timer and then turns rs on right side for 1 sec then turns rs off
rs.setOutput("top", true)
sleep(5)
rs.setOutput("top", false)
sleep(tenMin)
rs.setOutput("right", true)
sleep(1)
rs.setOutput("right", false)
end
function twentyTimer() --starts 20 min timer and then turns rs on right side for 1 sec then turns rs off
rs.setOutput("top", true)
sleep(5)
rs.setOutput("top", false)
sleep(twentyMin)
rs.setOutput("right", true)
sleep(1)
rs.setOutput("right", false)
end
function thirtyTimer() --starts 30 min timer and then turns rs on right side for 1 sec then turns rs off
rs.setOutput("top", true)
sleep(5)
rs.setOutput("top", false)
sleep(thirtyMin)
rs.setOutput("right", true)
sleep(1)
rs.setOutput("right", false)
end
local ten = 1 --sets value to match against coinCount to ensure the correct function above is called
local twenty = 2
local thirty = 3
print("How Much Time Would You Like To Buy?")
print("1 Gold Coin = 10 Minutes.")
print("You May ONLY Buy Up To 30 Minutes.")
print("Enter Number Of Gold Coins:")
write("Coins: ")
local goldCoins = tonumber(read()) --asks user for input of how many coins they will deposit
repeat
os.pullEvent("redstone") --# wait for redstone events
coinCount = coinCount + 1
until coinCount == goldCoins
term.clear()
term.setCursorPos(1,1)
print("Thank You!")
term.setCursorPos(1,2)
print("Please Enjoy!")
term.setCursorPos(1,3)
print("You Have 5 Seconds To Enter!")
term.setCursorPos(1,4)
print("You Have: ")
print(10*coinCount.." Minutes!") --this prints coinCount, times 10 to tell the user the amount of minutes they have. this works and if i put 1 for goldCoins value i get a print saying 10 minutes, if i put 2 i get 20 minutes.
if coinCount == thirty then --if coinCount, coins they inserted, is equal to goldCoins, how many they said, then start 30 minute timer
thirtyTimer()
elseif coinCount == twenty then --if coinCount, coins they inserted, is equal to goldCoins, how many they said, then start 20 minute timer
elseif coinCount == ten then --if coinCount, coins they inserted, is equal to goldCoins, how many they said, then start 10 minute timer
tenTimer()
else
os.reboot()
end
term.clear()
term.setCursorPos(1,1)
print("Thank You! Come again.")
for i = 1, 5 do
print("Rebooting in: "..i)
sleep(1)
end
os.reboot()
EDIT: I checked the value of coinCount because i thought the os.pullevent("redstone") was counting up twice, once for rs turning on, and once for it turning off. if this is the case it's not being reflected in coinCount value.
EDIT2: I played around with your code you posted. Worked beautifully like mine, except same issue as with the other code, I like yours though, much nicer and cleaner :)/>
Here's what i have:
Spoiler
term.clear()
term.setCursorPos(1,1)
local tenMin = 6
local twentyMin = 12
local thirtyMin = 18
local coinCount = 0 --coins inserted
local function beginTimer(amount)
rs.setOutput("top", true)
sleep(5)
rs.setOutput("top", false)
local myTimer = os.startTimer(amount) --# start a timer for the amount of time specified, capture the timer's unique id with the variable myTimer
repeat --# start an infinite loop
local _, id = os.pullEvent("timer") --# pull only timer events
until id == myTimer --# end the loop when our timer has fired
rs.setOutput("right", true)
sleep(1)
rs.setOutput("right", false)
end
local ten = 1 --sets value to match against coinCount to ensure the correct function above is called
local twenty = 2
local thirty = 3
print("How Much Time Would You Like To Buy?")
print("1 Gold Coin = 10 Minutes.")
print("You May ONLY Buy Up To 30 Minutes.")
print("Enter Number Of Gold Coins:")
write("Coins: ")
local goldCoins = tonumber(read()) --asks user for input of how many coins they will deposit
repeat
os.pullEvent("redstone") --# wait for redstone events
coinCount = coinCount + 1
until coinCount == goldCoins
term.clear()
term.setCursorPos(1,1)
print("Thank You!")
term.setCursorPos(1,2)
print("Please Enjoy!")
term.setCursorPos(1,3)
print("You Have 5 Seconds To Enter!")
term.setCursorPos(1,4)
print("You Have: ")
print(10*coinCount.." Minutes!") --this prints coinCount, times 10 to tell the user the amount of minutes they have. this works and if i put 1 for goldCoins value i get a print saying 10 minutes, if i put 2 i get 20 minutes.
beginTimer(coinCount * 6)
term.clear()
term.setCursorPos(1,1)
print("Thank You!")
term.setCursorPos(1,2)
print("Please Enjoy!")
term.setCursorPos(1,3)
print("You Have 5 Seconds To Enter!")
term.setCursorPos(1,4)
print("You Have: ")
print(10*coinCount.." Minutes!") --this prints coinCount, times 10 to tell the user the amount of minutes they have. this works and if i put 1 for goldCoins value i get a print saying 10 minutes, if i put 2 i get 20 minutes.
term.clear()
term.setCursorPos(1,1)
print("Thank You! Come again.")
for i = 1, 5 do
print("Rebooting in: "..i)
sleep(1)
end
os.reboot()