8 posts
Posted 14 June 2012 - 10:37 AM
SL7205 here! This is my first program on ComputerCraft. And it is contain many bugs.
If someone can help me please tell me.
Link:
http://pastebin.com/sQuSRWphThank you.
SL7205
992 posts
Posted 14 June 2012 - 10:53 AM
next time use the ASK a PRO section but here is a fixed ver
Spoiler
password = "start"
stop = "stop"
pump2 = "pump2"
stop2 = "stop2"
while true do
term.clear()
term.setCursorPos(1,1)
print "Inventionscreative Control Panel"
write "Please type in what to do> "
input = read()
if input == password then
redstone.setOutput ("back",true)
sleep(1)
end
if input == stop then
redstone.setOutput ("back",false)
sleep(1)
end
if input == pump2 then
redstone.setOutput ("left",true)
sleep(1)
end
if input == stop2 then
redstone.setOutput ("left",false)
sleep(1)
else
print "No Such Process!"
sleep(1)
end
end
18 posts
Posted 14 June 2012 - 12:33 PM
Why do you make static variables if you are only gonna use ones.
Instead of :
password = "start"
if input == password then
redstone.setOutput ("back",true)
sleep(1)
end
Try this :
if input == "start" then
redstone.setOutput ("back",true)
sleep(1)
end
And try to use elseif!
Here is the fixed code :
while true do
term.clear()
term.setCursorPos(1,1)
print "Inventionscreative Control Panel"
write "Please type in what to do> "
input = read()
if input == "start" then
redstone.setOutput ("back",true)
sleep(1)
elseif input == "stop" then
redstone.setOutput ("back",false)
sleep(1)
elseif input == "pump2" then
redstone.setOutput ("left",true)
sleep(1)
elseif input == "stop2" then
redstone.setOutput ("left",false)
sleep(1)
else
print "No Such Process!"
sleep(1)
end
end
This way it's looks way cleaner and it will properly work better!
992 posts
Posted 14 June 2012 - 12:52 PM
all i was doing is fixing the code . My intention was not to rewrite it or i would have used a table to store the variables and a for loop to check if it was the correct one then execute the required change in Redstone sate.
445 posts
Posted 14 June 2012 - 12:53 PM
Why do you make static variables if you are only gonna use ones.
Instead of :
password = "start"
if input == password then
redstone.setOutput ("back",true)
sleep(1)
end
Try this :
if input == "start" then
redstone.setOutput ("back",true)
sleep(1)
end
And try to use elseif!
Here is the fixed code :
while true do
term.clear()
term.setCursorPos(1,1)
print "Inventionscreative Control Panel"
write "Please type in what to do> "
input = read()
if input == "start" then
redstone.setOutput ("back",true)
sleep(1)
elseif input == "stop" then
redstone.setOutput ("back",false)
sleep(1)
elseif input == "pump2" then
redstone.setOutput ("left",true)
sleep(1)
elseif input == "stop2" then
redstone.setOutput ("left",false)
sleep(1)
else
print "No Such Process!"
sleep(1)
end
end
This way it's looks way cleaner and it will properly work better!
Cause if code gets longer it is easier to have some variables on the top that you can change instead of jumping through the code :(/>/>
18 posts
Posted 14 June 2012 - 02:18 PM
Why do you make static variables if you are only gonna use ones. Instead of :
password = "start" if input == password then redstone.setOutput ("back",true) sleep(1) end
Try this :
if input == "start" then redstone.setOutput ("back",true) sleep(1) end
And try to use elseif! Here is the fixed code :
while true do term.clear() term.setCursorPos(1,1) print "Inventionscreative Control Panel" write "Please type in what to do> " input = read() if input == "start" then redstone.setOutput ("back",true) sleep(1) elseif input == "stop" then redstone.setOutput ("back",false) sleep(1) elseif input == "pump2" then redstone.setOutput ("left",true) sleep(1) elseif input == "stop2" then redstone.setOutput ("left",false) sleep(1) else print "No Such Process!" sleep(1) end end
This way it's looks way cleaner and it will properly work better!
Cause if code gets longer it is easier to have some variables on the top that you can change instead of jumping through the code :(/>/>
I don't think he/she needs the string another time in the future and with this method you make the script only shorter and cleaner?
And btw, don't you need to jumpback to see what the name of the variable is?
I can't see why this possible needs variables…
445 posts
Posted 14 June 2012 - 02:38 PM
Why do you make static variables if you are only gonna use ones. Instead of :
password = "start" if input == password then redstone.setOutput ("back",true) sleep(1) end
Try this :
if input == "start" then redstone.setOutput ("back",true) sleep(1) end
And try to use elseif! Here is the fixed code :
while true do term.clear() term.setCursorPos(1,1) print "Inventionscreative Control Panel" write "Please type in what to do> " input = read() if input == "start" then redstone.setOutput ("back",true) sleep(1) elseif input == "stop" then redstone.setOutput ("back",false) sleep(1) elseif input == "pump2" then redstone.setOutput ("left",true) sleep(1) elseif input == "stop2" then redstone.setOutput ("left",false) sleep(1) else print "No Such Process!" sleep(1) end end
This way it's looks way cleaner and it will properly work better!
Cause if code gets longer it is easier to have some variables on the top that you can change instead of jumping through the code :(/>/>
I don't think he/she needs the string another time in the future and with this method you make the script only shorter and cleaner?
And btw, don't you need to jumpback to see what the name of the variable is?
I can't see why this possible needs variables…
Not if you label the variables properly
And dunno :)/>/> just saying it might be good practice in longer scripts or scripts that could get longer in the future to put up a few configuration variables on top rather than hardcoding stuff
992 posts
Posted 14 June 2012 - 04:04 PM
Or you could compact it and make it more universal.
Spoiler
local tSides = rs.getSides()
local n = nil
local tCommandList = {
{"pump1",n,n,n,1,n,n},
{"stop1",n,n,n,0,n,n},
{"pump2",n,n,n,n,1,n},
{"stop2",n,n,n,n,0,n}
}
while true do
term.clear()
term.setCursorPos(1,1)
write ("Inventionscreative Control PanelnPlease type in what to do> n")
local sInput = read()
for i = 1, #tCommandList do
if sInput == tCommandList[i][1] then
for o = 1,6 do
if tCommandList[i][o+1] == 1 then
rs.setOutput(tSides[o],true)
elseif tCommandList[i][o+1] == 0 then
rs.setOutput(tSides[o],false)
end
end
end
end
end
445 posts
Posted 14 June 2012 - 06:38 PM
See that looks nice XD