60 posts
Posted 03 November 2018 - 10:15 PM
Hi, so here's the rundown.
Trying to countdown from 5 to 0 but also look for a keypress using os.pullEvent("key"). I've managed to get it so that if there is
no keypress that it will successfully count all the way down and if there
is a keypress that it will cancel the countdown, clear the screen, and NOT continue to print the countdown. However shortly after it clears the screen and prints the new menu it exits out of the script. Not sure why? Maybe someone here could give me a hand! I've tried all sorts of 'return' uses and 'break' uses. Latest endeavor was using a variable to declare the state of the event() function and have the start() function check it routinely.
function test()
end
function event()
runtime = true
os.pullEvent("key")
runtime = false
term.clear()
term.setCursorPos(1,1)
term.setTextColor(1)
term.write("Enter the distance you'd like this CnS bot to dig.")
while true do
local input = io.read()
input = tonumber(distance)
if distance then
break
end
print("Please enter an actual number.")
end
end
function start()
print("By default this CnS bot will mine a distance of 128 blocks")
print("Press any button to change this value")
x, y = term.getCursorPos()
s = 5
while s > 0 do
if runtime == true then
term.setTextColor(8)
term.write(s)
sleep(1)
s = s - 1
term.setCursorPos(x, y)
else
break
end
end
end
parallel.waitForAny(event, start)
--turtle.getFuelLevel(
Anyone's help would be appreciated! Thank you!
749 posts
Location
BOO!!
Posted 04 November 2018 - 12:52 AM
Maybe because your using waitForAny instead of waitForAll?
60 posts
Posted 04 November 2018 - 01:05 AM
I tried to use wairForAll before and it wasn't working either.
EDIT: Well on second thought. Let me give that a look.
Edited on 04 November 2018 - 12:06 AM
60 posts
Posted 04 November 2018 - 01:14 AM
I believe that's fixed the issue. I'm not sure what's changed since I tried this last but I'll come back here if anything has gone to hell again! Thanks!
7083 posts
Location
Tasmania (AU)
Posted 04 November 2018 - 03:04 AM
This isn't really a good place to be using the parallel API in the first place. Let's simplify a bit:
Spoiler
print("By default this CnS bot will mine a distance of 128 blocks")
print("Press any button to change this value")
local x, y = term.getCursorPos()
local s = 5
local distance
local myTimer = os.startTimer(0)
while s >= 0 do
local event, param = os.pullEvent()
if event == "timer" and param == myTimer then
term.setTextColor(8)
term.write(s)
s = s - 1
term.setCursorPos(x, y)
myTimer = os.startTimer(1)
elseif event == "key" then
term.clear()
term.setCursorPos(1,1)
term.setTextColor(1)
term.write("Enter the distance you'd like this CnS bot to dig.")
while true do
distance = tonumber(read())
if distance then
break
end
print("Please enter an actual number.")
end
break
end
end
--turtle.getFuelLevel(
60 posts
Posted 04 November 2018 - 04:10 AM
Well I'd love to try this and see for myself but I can't get 'pastebin get' to work for me. AND I'm using a later version then 1.8 ( I saw your other post after a quick google search).
2427 posts
Location
UK
Posted 04 November 2018 - 10:24 AM
What are you trying to get from pastebin and what is the error that you get?
60 posts
Posted 04 November 2018 - 07:00 PM
Well specifically I was trying to pull his revised version of my program but it hasn't worked for anything thus far. I can 'pastebin put' files but not 'get'.
Here is the link I was using.
https://pastebin.com/kvr3tzaDAnd here's the error.
2427 posts
Location
UK
Posted 05 November 2018 - 05:35 PM
Your image has borked
1220 posts
Location
Earth orbit
Posted 05 November 2018 - 08:20 PM
I think I see what's happening. When you're using
pastebin get you only need the unique identifier for the paste, not the entire URL.
pastebin get kvr3tza0 test
60 posts
Posted 08 November 2018 - 06:21 AM
Ah tyty
7083 posts
Location
Tasmania (AU)
Posted 09 November 2018 - 12:03 AM
Note that there's no need to use pastebin at all if you're in singleplayer mode, or otherwise have easy access to your world save folder. Look for the "computers" folder within that.