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

[Error] getting a error

Started by codyteen, 16 April 2012 - 05:41 AM
codyteen #1
Posted 16 April 2012 - 07:41 AM
Im getting a error when i run this program
while true do
os.sleep(.5)
number = math.random(1,16)
print (number)
if number == "1" then
rs.setBundledOutput("back", colors.white)
os.sleep(.5)
rs.setBundledOutput("back", rs.getBundledOutput("back") - colors.white)
end
if number == "2" then
rs.setBundledOutput("back", colors.orange)
os.sleep(.5)
rs.setBundledOutput("back", rs.getBundledOutput("back") - colors.orange)
end
if number == "3" then
rs.setBundledOutput("back", colors.magenta)
os.sleep(.5)
rs.setBundledOutput("back", rs.getBundledOutput("back") - colors.magenta)
end
if number == "4" then
rs.setBundledOutput("back", colors.lightblue)
os.sleep(.5)
rs.setBundledOutput("back", rs.getBundledOutput("back") - colors.lightblue)
end
if number == "5" then
rs.setBundledOutput("back", colors.yellow)
os.sleep(.5)
rs.setBundledOutput("back", rs.getBundledOutput("back") - colors.yellow)
end
if number == "6" then
rs.setBundledOutput("back", colors.lime)
os.sleep(.5)
rs.setBundledOutput("back", rs.getBundledOutput("back") - colors.lime)
end
if number == "7" then
rs.setBundledOutput("back", colors.pink)
os.sleep(.5)
rs.setBundledOutput("back", rs.getBundledOutput("back") - colors.pink)
end
if number == "8" then
rs.setBundledOutput("back", colors.gray)
os.sleep(.5)
rs.setBundledOutput("back", rs.getBundledOutput("back") - colors.gray)
end
if number == "9" then
rs.setBundledOutput("back", colors.lightgray)
os.sleep(.5)
rs.setBundledOutput("back", rs.getBundledOutput("back") - colors.lightgray)
end
if number == "10" then
rs.setBundledOutput("back", colors.cyan)
os.sleep(.5)
rs.setBundledOutput("back", rs.getBundledOutput("back") - colors.cyan)
end
if number == "11" then
rs.setBundledOutput("back", colors.purple)
os.sleep(.5)
rs.setBundledOutput("back", rs.getBundledOutput("back") - colors.purple)
end
if number == "12" then
rs.setBundledOutput("back", colors.blue)
os.sleep(.5)
rs.setBundledOutput("back", rs.getBundledOutput("back") - colors.blue)
end
if number == "13" then
rs.setBundledOutput("back", colors.brown)
os.sleep(.5)
rs.setBundledOutput("back", rs.getBundledOutput("back") - colors.brown)
end
if number == "14" then
rs.setBundledOutput("back", colors.green)
os.sleep(.5)
rs.setBundledOutput("back", rs.getBundledOutput("back") - colors.green)
end
if number == "15" then
rs.setBundledOutput("back", colors.red)
os.sleep(.5)
rs.setBundledOutput("back", rs.getBundledOutput("back") - colors.red)
end
if number == "16" then
rs.setBundledOutput("back", colors.black)
os.sleep(.5)
rs.setBundledOutput("back", rs.getBundledOutput("back") - colors.black)
end
end
im kind of new but its my first time doing a number generator
there will be alot more like 1-64
Luanub #2
Posted 16 April 2012 - 08:31 AM
The problem is the clear. Its an invalid command. You need to use either shell.run("clear") which will clear the screen and place the cursor at 1,1. Or you can use term.clear() which will clear the screen leaving the cursor where it is, you can then use term.setCursorPos(x, y) to set where you want the cursor.
codyteen #3
Posted 16 April 2012 - 08:27 PM
bump i need help with the new code
OmegaVest #4
Posted 16 April 2012 - 08:38 PM
You could add a while loop that has 2 conditionals in it like so:


while true do
   os.startTimer(waitTime)  -- set waitTime to the number of seconds it will wait until it repeats
   event, attrib, attrib1 = os.pullEventsRaw()
   if event == "timer" then
	  --Your code here
   elseif event = "key" then   -- You can also add a custom key here to make it so esc doesn't kill it.
	  break
   elseif event == "terminate" then  -- I think this one works. For some reason, I cannot remember the CRTL-T event that pullEventsRaw spits out. And I can't presently test it.
	  break
   end
end
codyteen #5
Posted 16 April 2012 - 09:04 PM
thx for that i fix it now when i gens the number it shows it but it is not giving power to the bundled cable
changed the code on the main post
MysticT #6
Posted 16 April 2012 - 09:28 PM
That's because you are comparing a number to a string, change the if lines from:

if number == "1" then
to:

if number == 1 then
Remove the quotation marks, that's for strings, and you have numbers.
codyteen #7
Posted 16 April 2012 - 09:28 PM
thx