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

HELP HELP HELP

Started by coolvolsfan, 30 December 2012 - 07:19 PM
coolvolsfan #1
Posted 30 December 2012 - 08:19 PM
… im wanting my code to be … when its false it will restart … and not go but if true it will … how do i fix it … here is what i have: can someone please help


print (redstone.getInput("right"))
if"true"
print "opening door 1R in 5 sec"
sleep(1)
print "opening door 1R in 4 sec"
sleep(1)
print "opening door 1R in 3 sec"
sleep(1)
print "opening door 1R in 2 sec"
sleep(1)
print "opening door 1R in 1 sec"
sleep(1)
print "door is open … closing in 5 sec"
redstone.setBundledOutput("back", colors.white)
sleep(5)
redstone.setBundledOutput("back", 0)
print "door is closed"
sleep (5)
os.reboot()
if"false"
os.reboot()
ChunLing #2
Posted 30 December 2012 - 08:53 PM
Nice screams for help…now let us hear you beg for mercy!

Okay, the conditional syntax you want is:
if conditional then -- conditional can be a value, variable, expression, or function, any values other than false or nil cause the code to be executed
-- your conditional code here
end
Kingdaro #3
Posted 30 December 2012 - 08:56 PM
I think this should do what you need:


-- do this entire code here forever
while true do
	-- wait until one of the redstone inputs on the computer changes
	os.pullEvent("redstone")

	-- check if we have an RS input on the right
	if redstone.getInput("right") then
		-- self explanatory
		print "opening door 1R in 5 sec"
		sleep(1)
		print "opening door 1R in 4 sec"
		sleep(1)
		print "opening door 1R in 3 sec"
		sleep(1)
		print "opening door 1R in 2 sec"
		sleep(1)
		print "opening door 1R in 1 sec"
		sleep(1)
		print "door is open ... closing in 5 sec"
		redstone.setBundledOutput("back", colors.white)
		sleep(5)
		redstone.setBundledOutput("back", 0)
		print "door is closed"
	end
end

Commented just for you.
remiX #4
Posted 30 December 2012 - 09:47 PM

print "opening door 1R in 5 sec"
sleep(1)
print "opening door 1R in 4 sec"
sleep(1)
print "opening door 1R in 3 sec"
sleep(1)
print "opening door 1R in 2 sec"
sleep(1)
print "opening door 1R in 1 sec"
sleep(1)
can be changed into

for i = 5, 1, -1 do
    print("Opening door 1R in " .. i .. " sec")
    sleep(1)
end
coolvolsfan #5
Posted 31 December 2012 - 04:33 AM
king … i like your help u seem like a smart guy but your program is like what i want … but just Alltel different … i want it to since if the power is on if so do the commands and then restart the computer if power is off .. just restart it with no commands … because on that computer I'm using … it has to open 3 doors so it cant take over the computer
coolvolsfan #6
Posted 31 December 2012 - 05:13 AM
this is sorda what i whant … but if the imput is false (using my code) the computer still runs can u fix it …


print (redstone.getInput("right"))
	   if "true" then -- if imput is on run the commands to the 1st "end
		  print "opening door 3R in 5 sec"
		  sleep(1)
		  print "opening door 3R in 4 sec"
		  sleep(1)
		  print "opening door 3R in 3 sec"
		  sleep(1)
		  print "opening door 3R in 2 sec"
		  sleep(1)
		  print "opening door 3R in 1 sec"
		  sleep(1)
		  print "door is open ... closing in 5 sec"
		  redstone.setBundledOutput("back", colors.blue)
		  sleep(5)
		  redstone.setBundledOutput("back", 0)
		  print "door is closed"
		  sleep (5)
		  os.reboot()
	   end
	   if "false" then -- if the imput is off do it just restarts the computer
		  os.reboot()
	   end
remiX #7
Posted 31 December 2012 - 05:36 AM
term.clear() term.setCursorPos(1,1)
while true do -- Infinite Loop
    os.pullEvent('redstone') -- Acts as a yield and will only continue until a redstone event happens.
    if redstone.getInput("right") then -- if imput is on run the commands to the 1st "end
        for i = 5, 1, -1 do
            term.setCursorPos(1,1)
            term.clearLine()
            print("Door is opening in " .. i .. (i == 1 and " second." or " seconds."))
            sleep(1)
        end
        print ("Door is open ... closing in 5 seconds.")
        redstone.setBundledOutput("back", colors.blue)
        sleep(5)
        redstone.setBundledOutput("back", 0)
        print "door is closed"
        sleep (5)
        os.reboot()
    end
end
coolvolsfan #8
Posted 31 December 2012 - 05:42 AM
remi i love the code … but what happens if the current is off
coud make it where it just restarts if off and runs nothing just restarts
coolvolsfan #9
Posted 31 December 2012 - 12:42 PM
can someone ,,, help
IvanVance #10
Posted 31 December 2012 - 12:58 PM
If True
print "opening door 1R in 5 sec"
sleep(1)
print "opening door 1R in 4 sec"
sleep(1)
print "opening door 1R in 3 sec"
sleep(1)
print "opening door 1R in 2 sec"
sleep(1)
print "opening door 1R in 1 sec"
sleep(1)
print "door is open … closing in 5 sec"
redstone.setBundledOutput("back", colors.white)
sleep(5)
redstone.setBundledOutput("back", 0)
print "door is closed"
sleep (5)
os.reboot()
Else
os.reboot
or something like that
coolvolsfan #11
Posted 31 December 2012 - 01:11 PM
ivan how is this helpfull
remiX #12
Posted 31 December 2012 - 01:53 PM

term.clear() term.setCursorPos(1,1)
    if redstone.getInput("right") then -- if imput is on run the commands to the 1st "end
        for i = 5, 1, -1 do
            term.setCursorPos(1,1)
            term.clearLine()
            print("Door is opening in " .. i .. (i == 1 and " second." or " seconds."))
            sleep(1)
        end
        print ("Door is open ... closing in 5 seconds.")
        redstone.setBundledOutput("back", colors.blue)
        sleep(5)
        redstone.setBundledOutput("back", 0)
        print "door is closed"
        sleep (5)
        os.reboot()
    end

There we go.
coolvolsfan #13
Posted 31 December 2012 - 02:19 PM
:D/> thank you