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

Elevator Platform Program

Started by Dailias, 21 June 2014 - 02:30 PM
Dailias #1
Posted 21 June 2014 - 04:30 PM
I want to build a platform as an elevator. The construction with frames and frame motors working properly. But the program does not. When a signal is received Redstone to 5 pulses to a motor go 5 seconds serviced and 5 impulse to another motor.

This is my program: http://pastebin.com/uH2QctWZ

It works once and then comes the error: startup:7: Too long without yielding

I´m not realy good with computercraft… pleace help me xD

Tanks
Dailias
Dailias #2
Posted 21 June 2014 - 04:42 PM
Sorry i have fix it… It´s better to read the forum first :D/>

New Code: http://pastebin.com/J020d1KY

it works without error.

but can i write it better?
Lignum #3
Posted 21 June 2014 - 04:44 PM
When the computer isn't provided with a redstone signal, it will loop without yielding, which doesn't allow other computers' programs to run. You need to yield when there is no redstone signal. The simplest way to do this is to call sleep(0).

So…

if rs.getInput("left") == true then
    ....
else
   sleep(0)
end
Dailias #4
Posted 21 June 2014 - 05:00 PM
Thanks Lignum :)/>

is os.pullEvent() in line 7 ok? i have try it bevor i read yout answare and it works too
Lignum #5
Posted 21 June 2014 - 10:19 PM
Thanks Lignum :)/>

is os.pullEvent() in line 7 ok? i have try it bevor i read yout answare and it works too

Yes, that's okay. If you're using os.pullEvent, you could use os.pullEvent("redstone") which is better than sleeping.