This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
IndustrialLemon's profile picture

Issue involving parallel. Help appreciated.

Started by IndustrialLemon, 03 November 2018 - 09:15 PM
IndustrialLemon #1
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!
EveryOS #2
Posted 04 November 2018 - 12:52 AM
Maybe because your using waitForAny instead of waitForAll?
IndustrialLemon #3
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
IndustrialLemon #4
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!
Bomb Bloke #5
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(
IndustrialLemon #6
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).
Lupus590 #7
Posted 04 November 2018 - 10:24 AM
What are you trying to get from pastebin and what is the error that you get?
IndustrialLemon #8
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/kvr3tzaD

And here's the error.
Lupus590 #9
Posted 05 November 2018 - 05:35 PM
Your image has borked
Dog #10
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
IndustrialLemon #11
Posted 08 November 2018 - 06:21 AM
Ah tyty
Bomb Bloke #12
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.