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

Too long without yielding

Started by WirelessDude569, 10 April 2012 - 07:57 PM
WirelessDude569 #1
Posted 10 April 2012 - 09:57 PM
Hi, ive been testing this program i made, but i keep getting this fault: bios:207: Too long without yielding.
Code:

x = 1
while x == 1 do shell.run("clear")
end
write ("Type Continue")
com = read ()
if com == ("Continue") then
print ("Connectint to login server...")
sleep(5)
write ("Conection found! Connect to RedNetV3.1?")
ans = read ()
if ans == "Yes" then
print ("Connecting...")
sleep(5)
print ("Connected to RedNetV3.1")
end
write ("Enter username")
usr = read ()
if usr == "WirelessDude569" then print ("Username: OK!")
write ("Enter password")
pass = read ()
if pass == "Fishtaco" then
print ("Passworg: OK!")
print ("========WirelessDude569's Main Computer========")
print ("==Commands: ViewStatus==Views machines/pumps===")
print ("============Traps=======Views traps============")
print ("===============================================")
end
end
com2 = read ()
if com2 == ViewTraps then
shell.run("clear")
com3 = read ()
print ("=====Traps=====")
print ("=====TESLA=====")
print ("===="..TC.."======")
print ("===============")
print ("=====LAVA======")
print ("===="..LA.."======")
print ("===============")
print ("Commands")
print ("LAVA    ")
print ("TESLA   ")
if com3 == "LAVA" then
rs.getBundledInput("back", colors.white )
if true then print ("Deactivating lava trap...")
sleep(5)
print ("Lava trap deactivated.")
rs.setBundledOutput("bottom", colors.orange )
else
print ("Activating lava trap...")
sleep(5)
print ("Lava trap activated.")
rs.setBundledOutput("bottom", colors.white )
TC = rs.getBundledInput("back", colors.white )
if true then TC = "ON="
else print ("OFF")
end
end
elseif com3 == "TESLA" then
rs.getBundledInput("back", colors.orange )
if true then print ("Deactivating tesla coils...")
sleep(5)
print ("Tesla coils deactivated.")
rs.setBundledOutput("bottom", colors.orange )
LA = rs.getBundledInput("back", colors.orange )
if true then TC = "ON="
else TC = "ON="
end
end
end
end
end
Luanub #2
Posted 10 April 2012 - 10:01 PM
I think your problem is in some of your rs/if statements

Try changing

rs.getBundledInput("back", colors.white )
if true then print ("Deactivating lava trap...")

to

if rs.testBundledInput("back", colors.white ) then print("Deactivating lava trap...")
WirelessDude569 #3
Posted 11 April 2012 - 06:26 AM
I think your problem is in some of your rs/if statements

Try changing

rs.getBundledInput("back", colors.white )
if true then print ("Deactivating lava trap...")

to

if rs.testBundledInput("back", colors.white ) then print("Deactivating lava trap...")
Thanks! i'll try it :D/>/>
Edit: Nope, it didn't work… :P/>/> thanks for the try at least :)/>/>
Luanub #4
Posted 11 April 2012 - 09:33 AM
I should have looked closer. The problem is probably here…

x = 1
while x == 1 do shell.run("clear")
end


since nothing in the loop changes x to something other then 1 the loop runs infinitely, since there is no sleep in the loop you are getting the failure to yield error.
WirelessDude569 #5
Posted 11 April 2012 - 01:37 PM
I should have looked closer. The problem is probably here…

x = 1
while x == 1 do shell.run("clear")
end


since nothing in the loop changes x to something other then 1 the loop runs infinitely, since there is no sleep in the loop you are getting the failure to yield error.
Oh :P/>/> Thanks a LOT! this should do it :D/>/>
Edit: And it didnt :)/>/>
Luanub #6
Posted 11 April 2012 - 08:29 PM
The problem is the way you are working your if statements. You dont want to run every if until the end of the script. So you want to

if something == something then do stuff end
if something == something then do more stuff end

or

if something == something then do stuff
elseif something == somethingElse then do other stuff
end

You can nest if statements within if statements as long as you are ending them when the logical steps are completed and prior to moving on to the next if.

Here is the code fixed to where it will run as I think you intended.
Spoiler

local x = 1
local TC = ""
local LA = ""

LA = rs.testBundledInput("back", colors.orange )
if LA == true then LA = "ON="
else LA = "Off"
end

TC = rs.testBundledInput("back", colors.white )
if TC == true then
TC = "ON="
else TC = "OFF"
end

while x == 1 do
shell.run("clear")
x = x + 1
end
write ("Type Continue: ")
com = read ()
if com == ("Continue") then
print ("Connectint to login server...")
sleep(5)
write ("Conection found! Connect to RedNetV3.1? ")
end
ans = read ()
if ans == "Yes" then
print ("Connecting...")
sleep(5)
print ("Connected to RedNetV3.1")
end
write ("Enter username")
usr = read ()
if usr == "WirelessDude569" then
print ("Username: OK!")
end
write ("Enter password")
pass = read ()
if pass == "Fishtaco" then
print ("Passworg: OK!")
print ("========WirelessDude569's Main Computer========")
print ("==Commands: ViewStatus==Views machines/pumps===")
print ("============Traps=======Views traps============")
print ("===============================================")
end
com2 = read ()
if com2 == "ViewTraps" then
shell.run("clear")
print ("=====Traps=====")
print ("=====TESLA=====")
print ("===="..TC.."======")
print ("===============")
print ("=====LAVA======")
print ("===="..LA.."======")
print ("===============")
print ("Commands")
print ("LAVA	")
print ("TESLA   ")
end
com3 = read ()
if com3 == "LAVA" then
if rs.testBundledInput("back", colors.white ) == true then
print ("Deactivating lava trap...")
sleep(5)
print ("Lava trap deactivated.")
rs.setBundledOutput("bottom", colors.orange )
else
print ("Activating lava trap...")
sleep(5)
print ("Lava trap activated.")
rs.setBundledOutput("bottom", colors.white )
end
TC = rs.testBundledInput("back", colors.white )
if TC == true then
TC = "ON="
else TC = "OFF"
end
elseif com3 == "TESLA" then
if rs.testBundledInput("back", colors.orange ) == true then
print ("Deactivating tesla coils...")
sleep(5)
print ("Tesla coils deactivated.")
rs.setBundledOutput("bottom", colors.orange )
LA = rs.testBundledInput("back", colors.orange )
if LA == true then LA = "ON="
else LA = "Off"
end
end
end

There are some holes in your code. When your checking the user inputs you never have an else statement telling it to do something when the wrong input is entered. It just skips what it would do and moves on to the next step. IE you enter the wrong username, it still progresses to the password, if you enter the wrong password it still progresses to menu.

if logic for something like this should be something like.

while true do
write "Enter Username: "
local uname = read()
if uname == "Luanub" then
  break
else
  print ("Invalid Username entered, try again")
end
end

while true do
write "Enter Password: "
local pass = read()
if pass == "abc123" then
  break
else
  print ("Invalid Username entered, try again")
end
end

There are of coarse multiple ways to do it, this is just one way. You can use different loops, functions etc.. Hope this helps.
Edited on 11 April 2012 - 06:41 PM
WirelessDude569 #7
Posted 11 April 2012 - 08:36 PM
The problem is the way you are working your if statements. You dont want to run every if until the end of the script. So you want to

if something == something then do stuff end
if something == something then do more stuff end

or

if something == something then do stuff
elseif something == somethingElse then do other stuff
end

You can nest if statements within if statements as long as you are ending them when the logical steps are completed and prior to moving on to the next if.

Here is the code fixed to where it will run as I think you intended.
Spoiler

local x = 1
local TC = ""
local LA = ""

LA = rs.testBundledInput("back", colors.orange )
if LA == true then LA = "ON="
else LA = "Off"
end

TC = rs.testBundledInput("back", colors.white )
if TC == true then
TC = "ON="
else TC = "OFF"
end

while x == 1 do
shell.run("clear")
x = x + 1
end
write ("Type Continue: ")
com = read ()
if com == ("Continue") then
print ("Connectint to login server...")
sleep(5)
write ("Conection found! Connect to RedNetV3.1? ")
end
ans = read ()
if ans == "Yes" then
print ("Connecting...")
sleep(5)
print ("Connected to RedNetV3.1")
end
write ("Enter username")
usr = read ()
if usr == "WirelessDude569" then
print ("Username: OK!")
end
write ("Enter password")
pass = read ()
if pass == "Fishtaco" then
print ("Passworg: OK!")
print ("========WirelessDude569's Main Computer========")
print ("==Commands: ViewStatus==Views machines/pumps===")
print ("============Traps=======Views traps============")
print ("===============================================")
end
com2 = read ()
if com2 == "ViewTraps" then
shell.run("clear")
com3 = read ()
print ("=====Traps=====")
print ("=====TESLA=====")
print ("===="..TC.."======")
print ("===============")
print ("=====LAVA======")
print ("===="..LA.."======")
print ("===============")
print ("Commands")
print ("LAVA	")
print ("TESLA   ")
end
if com3 == "LAVA" then
if rs.testBundledInput("back", colors.white ) == true then
print ("Deactivating lava trap...")
sleep(5)
print ("Lava trap deactivated.")
rs.setBundledOutput("bottom", colors.orange )
else
print ("Activating lava trap...")
sleep(5)
print ("Lava trap activated.")
rs.setBundledOutput("bottom", colors.white )
end
TC = rs.testBundledInput("back", colors.white )
if TC == true then
TC = "ON="
else TC = "OFF"
end
elseif com3 == "TESLA" then
if rs.testBundledInput("back", colors.orange ) == true then
print ("Deactivating tesla coils...")
sleep(5)
print ("Tesla coils deactivated.")
rs.setBundledOutput("bottom", colors.orange )
LA = rs.testBundledInput("back", colors.orange )
if LA == true then LA = "ON="
else LA = "Off"
end
end
end

There are some holes in your code. When your checking the user inputs you never have an else statement telling it to do something when the wrong input is entered. It just skips what it would do and moves on to the next step. IE you enter the wrong username, it still progresses to the password, if you enter the wrong password it still progresses to menu.

if logic for something like this should be something like.

while true do
write "Enter Username: "
local uname = read()
if uname == "Luanub" then
  break
else
  print ("Invalid Username entered, try again")
end
end

while true do
write "Enter Password: "
local pass = read()
if pass == "abc123" then
  break
else
  print ("Invalid Username entered, try again")
end
end

There are of coarse multiple ways to do it, this is just one way. You can use different loops, functions etc.. Hope this helps.
Thanks a lot :P/>/> yeah, i didnt add the "else" at the time, but i did it when i checked my other programs :D/>/> again, thanks!
Luanub #8
Posted 11 April 2012 - 08:41 PM
Yeah it looks like it is still very much a work in progress. Glad to help let me know if you need anymore help. I just made a couple more small changes to fix a couple things, might want to check the script above and make sure it matches what you grabbed.
WirelessDude569 #9
Posted 11 April 2012 - 09:03 PM
Yeah it looks like it is still very much a work in progress. Glad to help let me know if you need anymore help. I just made a couple more small changes to fix a couple things, might want to check the script above and make sure it matches what you grabbed.
Yeah, i've got to add some things and move some things and such, but i'll give you a shout if i need help :P/>/> (to the code to make the entire program complete)
WirelessDude569 #10
Posted 11 April 2012 - 09:07 PM
I tested the program and spotted a problem here:

com2 = read ()
if com2 == "ViewTraps" then
shell.run("clear")
print ("=====Traps=====")
print ("=====TESLA=====")
print ("===="..TC.."======")
print ("===============")
print ("=====LAVA======")
print ("===="..LA.."======")
print ("===============")
print ("Commands")
print ("LAVA    ")
print ("TESLA   ")
end
I believe i can fix it by adding sleep(1) like this:

com2 = read ()
if com2 == "ViewTraps" then
shell.run("clear")
sleep(1)
print ("=====Traps=====")
print ("=====TESLA=====")
print ("===="..TC.."======")
print ("===============")
print ("=====LAVA======")
print ("===="..LA.."======")
print ("===============")
print ("Commands")
print ("LAVA    ")
print ("TESLA   ")
end
Luanub #11
Posted 11 April 2012 - 09:13 PM
You could even add a really small sleep so its less noticeable. sleep(0.1) or so just so it pauses for a brief moment.
WirelessDude569 #12
Posted 11 April 2012 - 09:22 PM
You could even add a really small sleep so its less noticeable. sleep(0.1) or so just so it pauses for a brief moment.
oh :P/>/> I didnt know it could go under 1 sec :D/>/>