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

[Question] A way to loop a computer to wait for bee analyzer

Started by crimsonknight3, 26 February 2013 - 02:22 PM
crimsonknight3 #1
Posted 26 February 2013 - 03:22 PM
[Question] A way to loop a computer to wait for bee analyzer

Hey, i've spent all night trying to figure this out but i just keep getting error after error. I am trying to make a program repeat until the condition m.isBee(true) and then, once there is a bee present in the analyzer, display the table (and i wanted to put a press any key once bee is removed, to repeat the program again) this computer is solely for use for analyzing bees and i would rather have the program repeated and automated rather than having to run for every bee inserted. Here is the code i have so far(which is one of my non working tries):


repeat
m = peripheral.wrap("right")
if m.Bee(true) then
data = m.analyze()
for i,v in pairs(data) do print(i.."  "..tostring(v))
end
end
else if m.isBee(false) then
print("Please insert analyzed bee")
sleep(3)
end
until m.isBee(true)
end
SuicidalSTDz #2
Posted 26 February 2013 - 03:36 PM
[Question] A way to loop a computer to wait for bee analyzer

Hey, i've spent all night trying to figure this out but i just keep getting error after error. I am trying to make a program repeat until the condition m.isBee(true) and then, once there is a bee present in the analyzer, display the table (and i wanted to put a press any key once bee is removed, to repeat the program again) this computer is solely for use for analyzing bees and i would rather have the program repeated and automated rather than having to run for every bee inserted. Here is the code i have so far(which is one of my non working tries):


repeat
m = peripheral.wrap("right")
if m.Bee(true) then
data = m.analyze()
for i,v in pairs(data) do print(i.."  "..tostring(v))
end
end
else if m.isBee(false) then
print("Please insert analyzed bee")
sleep(3)
end
until m.isBee(true)
end
This should work:


m = peripheral.wrap("right")
repeat
 if m.Bee() == true then
   data = m.analyze()
   for i,v in pairs(data) do print(i.."  "..tostring(v)) end
 elseif m.isBee(false) then
   print("Please insert analyzed bee")
   sleep(3)
 end
until m.isBee() == true
Enlose this all within a "while true do" loop and you "should" be golden.
crimsonknight3 #3
Posted 27 February 2013 - 06:42 AM
Okay i am now getting an attempt to call nil, or more precisely startup:4: attempt to call nil. this is what ive got


while true do
m = peripheral.wrap("right")
repeat
  if m.isBee() == true then
	data = m.analyze()
	for i,v in pairs (data) do print(i.."  "..string(v)) end
  elseif m.isBee(false) then
	print ("Please insert analyzed bee")
	sleep(3)
  end
until m.isBee() == true
end

Okay ignoring what i wrote above, i found my mistake however now when i boot up the computer i just get a blank screen then the number 32, then the computer crashed( stuck at >_ flashing but not responding to any keypresses), not even ctrl + t would get any response, so in the end i had to break the computer and start over
crimsonknight3 #4
Posted 27 February 2013 - 07:55 AM
After running the program again i now get bios:-1: vm error: java.lang.NullPointer.Exception

[edit] after trying again but this time outside of the startup folder, i get analyze:7: Too long without yielding….
crimsonknight3 #5
Posted 27 February 2013 - 08:23 AM
Got it!! For anyone reading this trying to figure out how here is the code i used!:


while true do
m = peripheral.wrap("right")
repeat
if m.isBee() == true then
data = m.analyze()
for i,v in pairs(data) do print(i.."  "..tostring(v)) end
elseif m.isBee() == false then
print("Please insert analyzed bee")
sleep(3)
term.clear()
term.setCursorPos(1, 1)
end
until m.isBee() == true
end
crimsonknight3 #6
Posted 27 February 2013 - 08:25 AM
Oh wait nevermind…. when i DO put a bee in it repeats the m.analyze part over and over and over again until it crashes :s back to square one >.>

edit

Ive tried this but im still getting the same problems


while true do
m = peripheral.wrap("right")
repeat
if m.isBee() == true then
data = m.analyze()
for i.v in pair(data) do print(i.."  "..tostring(v)) end
function rawread()
bRead = true
while(bRead) do
local sEvent, param = os.pullEvent("key")
if (sEvent == "key") then
break
end
end
end
end
elseif m.isBee() == false then
print("please insert analyzed bee")
sleep(3)
term.clear()
term.setCursorPos(1, 1)
end
until m.isBee() == true
end

Now im wondering, if i was to put the if m.isBee() == false then at the beginning of the program, and repeat until m.isBee() == true just the first part of code, would that would? that way it would keep repeating the beginning until the bee is present, because as it stands i cant get it to pick up the elseif part of code and it just seems to try and run m.analyze and write a table even though there isnt a bee present…


EDIT: I've tidied the above and its working apart from me having to run it manually which i will figure out soon, but another question now, when writing the table to my monitor it tries writing all the data on one line, thus cutting most of it off, the font size is okay, but what should i do to get it to put the data into 2 columns like it does natively in the terminal? its 4 monitors connected in a square
Right heres the code

local monitor = peripheral.wrap("left")
m = peripheral.wrap("right")
monitor.setTextScale(1)
repeat
if m.isBee() == false then
monitor.write("please insert an analyzed bee")
sleep(3)
monitor.clear()
monitor.setCursorPos(1, 1)
elseif m.isBee() == true
monitor.clear()
monitor.setCursorPos(1, 1)
data = m.analyze()
for i,v in pairs(data) do monitor.write(i.." "..tostring(v)) end
end
until m.isBee() == true
crimsonknight3 #7
Posted 27 February 2013 - 10:30 AM
Okay, i actually did get it now!! Works on monitor, and works in a loop without errors or crashes :D/> :D/> Heres the code for those who may want :)/>


while true do
local monitor = peripheral.wrap("left")
m = peripheral.wrap("right")
monitor.setTextScale(0.5)
term.redirect(monitor)
repeat
if m.isBee() == false then
print("Please insert an analyzed bee")
sleep(3)
term.clear()
term.setCursorPos(1, 1)
elseif m.isBee() == true then
term.clear()
term.setCursorPos(1, )
data = m.analyze()
for i,v in pairs(data) do print(i.." "..tostring(v)) end
sleep(10)
end
until m.isBee() == true
end