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

After a Sleep(2) the Console Prompt no longer shows up

Started by perfect007, 01 November 2012 - 12:23 AM
perfect007 #1
Posted 01 November 2012 - 01:23 AM
Hi all,

Here is my code for driving my moving platform forward:

function LedPulse(color, age)
rs.setBundledOutput("left", color)
sleep(age)
rs.setBundledOutput("left", 0)
end

function Forward()
LedPulse(16,2)
LedPulse(2048,2)
end

while true do
term.clear() term.setCursorPos(1,1)
write("Direction: \n1:Forward\n") local c=read()
if c=="1" then Forward()
else break
end
end
end

Here is the problem: The platform moves forward, but never prompts for me to choose a new Direction. However if I hit Esc then go back to my Console, the prompt is always back and ready for use. After some testing I found out the Console quits talking to me right after the first LedPulse happens (No writes appear on my screen after that point until I hit Esc and go back into the Console).

I did further tests using a program that just did a simple sleep then prompt and it worked…so I have no idea why it doesn't work in the program above. Why do I have to hit Esc and go back into the console just to have it prompt me for a new direction?

I had to write this by hand since I don't know how to copy it from Minecraft yet. Hopefully I didn't make any errors.

Thanks!
ChunLing #2
Posted 01 November 2012 - 05:26 PM
ComputerCraft files are stored in your world save under computerID (where ID is the computerID of the computer where the file is stored, type id into the console to get the computerID).

Your problem was probably being caused by the nature of CC computer events and the event queue. There are a number of discussions about how to prevent this kind of thing from happening, but if your program is now working then it's fine.
perfect007 #3
Posted 01 November 2012 - 06:47 PM
ComputerCraft files are stored in your world save under computerID (where ID is the computerID of the computer where the file is stored, type id into the console to get the computerID).

Your problem was probably being caused by the nature of CC computer events and the event queue. There are a number of discussions about how to prevent this kind of thing from happening, but if your program is now working then it's fine.

Hi Lua Maniac,

I appreciate the help in finding the files, will make coding much easier. It's still not working for me though, can you go into more detail about what you believe to be the issue and where I can find solutions? I've been googling my best, but still nothing.

Thanks!
perfect007 #4
Posted 01 November 2012 - 07:49 PM
After further testing I found out that it quits producing visible output here:

function LedPulse(color,age)
rs.setBundledOutput("left", color)<———-
sleep(age)
rs.setBundledOutput("left",0)
end

If I put Write statements after the setBundledOutput it does not write them. It does do all commands after this point, but no output is displayed. This is frustrating as I want to be able to rapidly input directional commands and I don't want to have to hit Esc each time.
remiX #5
Posted 01 November 2012 - 11:45 PM
You have 1 too many ends. Could that be the prob?

while true do
term.clear() term.setCursorPos(1,1)
write("Direction: n1:Forwardn") local c=read()
if c=="1" then Forward()
else break
end
end
end


while true do
    term.clear() term.setCursorPos(1,1)
    write("Direction: n1:Forwardn") local c=read()
    if c=="1" then Forward()
        else break
    end
end
perfect007 #6
Posted 02 November 2012 - 06:52 AM
Hmm, that does seem to be the case. But my program shouldn't run with extra Ends in it right?

Either way the lockup is in the LedPulse function after it sets a color. And by lockup, I mean it refuses to output any new data to the Console screen until I hit Esc and then right click the Console again. I'm unable to test the 'End' issue right now, but is it possible that something in the LedPulse function needs to be changed?

Thanks!
KaoS #7
Posted 02 November 2012 - 07:10 AM
try disconnecting the computer from the circuit, I think the relocation of the computer is the issue here
perfect007 #8
Posted 02 November 2012 - 11:16 AM
try disconnecting the computer from the circuit, I think the relocation of the computer is the issue here

This works, and the console does not freeze when nothing is connected. Now, how do I make it not freeze when it is connected?
ChunLing #9
Posted 02 November 2012 - 11:28 AM
Use a turtle.
perfect007 #10
Posted 02 November 2012 - 12:08 PM
Use a turtle.

The device is connected to a Bundled Circuit. Will a turtle work with that and will it get rid of my issue?
ChunLing #11
Posted 02 November 2012 - 12:23 PM
Hmm…it will fix the issues of moving the computer (modem falling off, program getting interrupted/losing data), computers aren't supposed to move and turtles are. Turtles should be able to interact with bundled cables just fine, but you need to synch things so that the interaction happens after both turtle and everything else moved.
KaoS #12
Posted 02 November 2012 - 01:50 PM
I don't think turtles will work either… there is only one way, moving manually
ChunLing #13
Posted 02 November 2012 - 03:02 PM
Yes, you have to issue a move command to the turtle, don't try to push it about with the frame.
KaoS #14
Posted 02 November 2012 - 10:16 PM
don't forget to put a cover over the frame under the turtle
perfect007 #15
Posted 04 November 2012 - 11:39 PM
The turtle doesn't seem to have access to the bundled cable. I ended up just allowing the user to type a distance amount which mostly solves the issue for me. Can't fly super fast, but that's Ok.
KaoS #16
Posted 05 November 2012 - 01:57 AM
I don't use computers for my flying machine that I recently built. I use levers and timers and wireless redstone. figured a very compact way