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

Does This Program Work?

Started by Kadecamz, 26 March 2012 - 06:00 PM
Kadecamz #1
Posted 26 March 2012 - 08:00 PM
I am a newb programmer, and I have created my first program that I wrote in free time at school. I want someone to please test it, and if it doesn't work to tell me what needs fixed. It is a redstone program that has you select the side to send the pulse.



Heres the code
__________________________________________________________________________________________________________

off = off

bottom = bottom

back = back

front = front

right = right

left = left

print ("Which side will the redstone pulse be sent?")

if "top" then
redstone.setOutput ("top", true)

if "bottom" then
redstone.setOutput ("bottom", true)

if "back" then
redstone.setOutput ("back", true)

if "front" then
redstone.setOutput ("front", true)

if "right" then
redstone.setOutput ("right", true)

if "left" then
redstone.setOutput ("left", true)

if "off" then
redstone.setOutput ("top", false)
redstone.setOutput ("bottom", false)
redstone.setOutput ("back", false)
redstone.setOutput ("front", false)
redstone.setOutput ("right", false)
redstone.setOutput ("left", false)
os.reboot()

print ("Proccessing………")

end
________________________________________________________________________________________________________


Constructive critisim would be welcome, remember this is my first script I didn't just copy! All is used from my mind.


If you're wondering how I learned it, I had to copy a password door script a couple times yesterday. That was kinda like studying lua for me.

os.shutdown()

print ("If you help, thank you!")

end
Casper7526 #2
Posted 26 March 2012 - 08:18 PM
No it does not work. You should definitely take some beginner lua tutorials as your basic syntax is quite off.

Take my interactive tutorial in the tutorials section when you get a chance.
ComputerCraftFan11 #3
Posted 26 March 2012 - 08:36 PM
I am a newb programmer, and I have created my first program that I wrote in free time at school. I want someone to please test it, and if it doesn't work to tell me what needs fixed. It is a redstone program that has you select the side to send the pulse.



Heres the code
__________________________________________________________________________________________________________


print ("Which side will the redstone pulse be sent?")
Input = read()

if Input == "top" then
redstone.setOutput ("top", true)

if Input =="bottom" then
redstone.setOutput ("bottom", true)

if Input =="back" then
redstone.setOutput ("back", true)

if Input =="front" then
redstone.setOutput ("front", true)

if Input =="right" then
redstone.setOutput ("right", true)

if Input =="left" then
redstone.setOutput ("left", true)

if Input =="off" then
redstone.setOutput ("top", false)
redstone.setOutput ("bottom", false)
redstone.setOutput ("back", false)
redstone.setOutput ("front", false)
redstone.setOutput ("right", false)
redstone.setOutput ("left", false)
os.reboot()

print ("Proccessing………")

end
________________________________________________________________________________________________________


Constructive critisim would be welcome, remember this is my first script I didn't just copy! All is used from my mind.


If you're wondering how I learned it, I had to copy a password door script a couple times yesterday. That was kinda like studying lua for me.

os.shutdown()

print ("If you help, thank you!")

end

It does not work but here's some tips:

To find what a user typed, write "anything" = read()
To make something happen if they type a command, do this:
(This time I'm gonna use input = read()
If input == "Hello" then
Print("Hi")
End

So I'd they type hello, it will print hi


I fixed the code for you*
kamnxt #4
Posted 26 March 2012 - 11:49 PM
Should be fixed:

s=rs.getSides()
while true do
print("Choose side:")
in = read()
if in =="top" or in =="left" or in =="right" or in =="back" or in =="front" or in =="bottom" then
rs.setOutput(in,true)
elseif in =="off" then
for i=1,#s do
rs.setOutput(s[i],false)
end
end
end
Phew, lua + smartphone ="Hard!"