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

Help please, Red motor gate not working

Started by mundaneafro1, 30 October 2012 - 09:21 PM
mundaneafro1 #1
Posted 30 October 2012 - 10:21 PM
i made a program in order to simply open and close a red motor gate.
I used two functions to turn on and off motors closing the gating and opening them. I then used an
"if" thingy ma bob to say if write open, open gate and if write close, close gate. I've been checking to
see if anything wrong with program but when ever i run it and try and type open or close it types c's for anything i press on the keyboard. I'll upload the program if anyone wants to see it to help.
Thanks for reading PLEASE HELP.
Lyqyd #2
Posted 30 October 2012 - 10:47 PM
Sounds like you have a read("c") in there somewhere.
Orwell #3
Posted 30 October 2012 - 10:52 PM
Indeed. Besides that, there's a thread below this one that does that:
http://www.computercraft.info/forums2/index.php?/topic/5585-problematic-else-command/
mundaneafro1 #4
Posted 31 October 2012 - 11:04 AM
thanks for da help, but i only have a read("close") and a read("open"), could that be anything to do with it? the read("close") or ("open") comes after an if, then a then so it runs the open/close function 4 times. Also i dont wanna copy someone else program coz im trying to learn it for myself. Ta
mundaneafro1 #5
Posted 31 October 2012 - 11:08 AM
just changed the read("close") to a read("boom") but now it only let me types b's
Doyle3694 #6
Posted 31 October 2012 - 11:14 AM
the read doesnt support multiple letters. check how read is built up in bios.lua and then make your own custom read for it
Doyle3694 #7
Posted 31 October 2012 - 11:16 AM
Or are you trying to make them type 'open' or close'?
Luanub #8
Posted 31 October 2012 - 11:24 AM
read is used to capture a users input so

local input = read() --will capture what you enter into the variable input

You can then check the input with an if statement:

if input == "open" then
  --do open stuff
elseif input == "close" then
  --do close stuff
end

We probably need to see your code to know what you're trying to accomplish to help you any further with this issue.

NOTE: putting anything in the () after the read will have what you type into the computer show on the screen as that character.
For an example when having a user enter a password a lot of people like the output on the screen to be *'s so they do

local input = read("*")
Edited on 31 October 2012 - 10:27 AM
mundaneafro1 #9
Posted 31 October 2012 - 11:29 AM
thanks, hw do i put my code on, im a complete noob at forums and CC. Changed it how u said with a for i =1,4 do close() so i repeats function close 4 times but its not working.
Harcole #10
Posted 31 October 2012 - 11:32 AM
http://computercraft.info/wiki/index.php?title=Making_a_Password_Protected_Door

This tutorial is what your trying to achieve, although as Luanub stated above instead of checking for for the "password" you need the double if statement one checking for the word open and another for the word close.

If you want to be able to see what was typed in to the computer then again, use Luanubs example above. Using read("*") where * can be anything will display that instead of the typed value.

You can either upload your code to Pastebin, or copy it from the source file and click the <> button on the post reply then paste your source code in to the window that opens.
mundaneafro1 #11
Posted 31 October 2012 - 11:32 AM
i know that already, thanks though, but im just trying now to set up a for loop so it repeats the function 4 times.
Harcole #12
Posted 31 October 2012 - 11:39 AM

function close
	-- close stuff
end


for 1, 4 do
	close();
end

If thats the code you've got and its not working try putting a print("Closing…"); line in after the close to see if it acutally gets that far…



function close
	-- close stuff
end


for 1, 4 do
	close();
	print("Closing..."); -- Debug!
end

Should give:

Closing…
Closing…
Closing…
Closing…

In the terminal screen if you haven't outputted to a monitor
mundaneafro1 #13
Posted 31 October 2012 - 11:42 AM
– heres the prgram im uusing

function open()
redstone.setOutput("back",true) –
sleep(1)
redstone.setOutput("back",false)
end

function close()
redstone.setOutput("left",true)
sleep(1)
redstone.setOutput("left".false)
end

print("Open or close? ")
input = read("")

if input == "close" then
for i=1,4 do
close()

elseif input== "open" then
for i =1,4 do
open()
end

– theres the code im using at the moment
mundaneafro1 #14
Posted 31 October 2012 - 11:47 AM
whenever i try running it now it says:

bios:206: [string "open"] :24: 'end' expected (to close 'for' at line 20)
mundaneafro1 #15
Posted 31 October 2012 - 11:51 AM
sorry fixed kinda but whenever i enter open or close it oonly does function once
mundaneafro1 #16
Posted 31 October 2012 - 11:55 AM
sorry once again, ive finally fixed it, turned out i ddint leave enogu time for redstone signal to register between repeated functions, ta for help though
Harcole #17
Posted 31 October 2012 - 12:18 PM
Glad you got it sorted, looking over your code I can't see why the sleep(1) wasn't enough but as long as its working :P/>/>