3 posts
Posted 13 April 2012 - 01:18 PM
So, I'm incredibly new to this whole prgramming thing, and for all I know I completely stormed off in the wrong direction, but I can't get a little piece of programming done to control the operation (triggering, open sequencing, close sequencing, etc.) of a 4x9 piston door I've been working on. I originally started this using the redpower logic circuits in an attempt to reverse engineer a youtube video I saw (4xY Expandable Piston Door) and was able to correctly reproduce the circuit but the correct variables for the counters and timers eluded me still. Hence why I came to the conclusion it would probably be much easier to figure out how to utilize the computer and budled cables in conjunction with a wireless redstone trigger to jo the job of what previously took a massive field of wiring.
Spoiler
Here is a visual of my test setup if it helps. I'm using a wireless redstone inputing to the top of a computer and secondarily to a toggle switch. I use the toggle switch to to send a right(open) and left(closed) signal to the computer in the hopes that it will select the right sequence and open shut the door. Then hopefully, the program continues to run until the wireless triggers another os.pullEvent. At least that's the idea :P/>/>
Wire Bundle comes in from bottom.
Piston wire colors are gray, green, orange, and brown.
Closing sequence is green on, green off, orange on, green on, green off, orange off, brown on, orange on.
Opening sequence is orange off, brown off, grey on, grey off, orange on, orange off, green on, grey on, grey off, green off, grey on grey off.Here's my attemp at the code for it
Spoiler
while true do
r, "top" = os.pullEvent
if r, "top" == "redstone" and rs.getInput("top") == true then
sleep(.2)
if rs.getInput("left") == true then
c = colors.combine(colors.green)
rs.setBundledOutput("bottom", c)
sleep(1)
c = colors.subtract(color.green)
rs.setBundledOutput("bottom", c)
sleep(1)
c = colors.combine(colors.orange)
rs.setBundledOutput("bottom", c)
sleep(1)
c = colors.combine(colors.green)
rs.setBundledOutput("bottom", c)
sleep(1)
c = colors.subtract(colors.green)
rs.setBundledOutput("bottom", c)
sleep(1)
c = colors.subtract(colors.orange)
rs.setBundledOutput("bottom", c)
sleep(1)
c = colors.combine(colors.brown)
rs.setBundledOutput("bottom", c)
sleep(1)
c = colors.combine(colors.orange)
rs.setBundledOutput("bottom", c)
end
else if rs.getInput("right") == true then
c = colors.subtract(colors.orange)
rs.setBundledOutput("bottom", c)
sleep(1)
c = colors.subtract(colors.brown)
rs.setBundledOutput("bottom", c)
sleep(1)
c = colors.combine(colors.grey)
rs.setBundledOutput("bottom", c)
sleep(1)
c = colors.subtract(colors.gray)
rs.setBundledOutput("bottom", c)
sleep(1)
c = colors.combine(colors.orange)
rs.setBundledOutput("bottom", c)
sleep(1)
c = colors.subtract(colors.orange)
rs.setBundledOutput("bottom", c)
sleep(1)
c = colors.combine(colors.green)
rs.setBundledOutput("bottom", c)
sleep(1)
c = colors.combine(colors.grey)
rs.setBundledOutput("bottom", c)
sleep(1)
c = colors.subtract(colors.grey)
rs.setBundledOutput("bottom", c)
sleep(1)
c = colors.subtract(colors.green)
rs.setBundledOutput("bottom", c)
sleep(1)
c = colors.combine(colors.gray)
rs.setBundledOutput("bottom", c)
sleep(1)
c = colors.subtract(colors.gray)
rs.setBundledOutput("bottom", c)
end
endAny help would be greatly appreciated. Just need a step in the right direction.
p.s. I know the sleep periods are rather long for a door of this nature, but I just want to get it running and fine tune it later.
378 posts
Location
In the TARDIS
Posted 13 April 2012 - 01:48 PM
you look for a redstone event? try this (and btw: you don't do "os.pullEvent" you use "os.pullEvent()")
while true do
event, side = os.pullEvent("redstone")
if rs.getInput("top") == true then
sleep(.2)
if rs.getInput("left") == true then
c = colors.combine(colors.green)
rs.setBundledOutput("bottom", c)
sleep(1)
c = colors.subtract(color.green)
rs.setBundledOutput("bottom", c)
sleep(1)
c = colors.combine(colors.orange)
rs.setBundledOutput("bottom", c)
sleep(1)
c = colors.combine(colors.green)
rs.setBundledOutput("bottom", c)
sleep(1)
c = colors.subtract(colors.green)
rs.setBundledOutput("bottom", c)
sleep(1)
c = colors.subtract(colors.orange)
rs.setBundledOutput("bottom", c)
sleep(1)
c = colors.combine(colors.brown)
rs.setBundledOutput("bottom", c)
sleep(1)
c = colors.combine(colors.orange)
rs.setBundledOutput("bottom", c)
end
else if rs.getInput("right") == true then
c = colors.subtract(colors.orange)
rs.setBundledOutput("bottom", c)
sleep(1)
c = colors.subtract(colors.brown)
rs.setBundledOutput("bottom", c)
sleep(1)
c = colors.combine(colors.grey)
rs.setBundledOutput("bottom", c)
sleep(1)
c = colors.subtract(colors.gray)
rs.setBundledOutput("bottom", c)
sleep(1)
c = colors.combine(colors.orange)
rs.setBundledOutput("bottom", c)
sleep(1)
c = colors.subtract(colors.orange)
rs.setBundledOutput("bottom", c)
sleep(1)
c = colors.combine(colors.green)
rs.setBundledOutput("bottom", c)
sleep(1)
c = colors.combine(colors.grey)
rs.setBundledOutput("bottom", c)
sleep(1)
c = colors.subtract(colors.grey)
rs.setBundledOutput("bottom", c)
sleep(1)
c = colors.subtract(colors.green)
rs.setBundledOutput("bottom", c)
sleep(1)
c = colors.combine(colors.gray)
rs.setBundledOutput("bottom", c)
sleep(1)
c = colors.subtract(colors.gray)
rs.setBundledOutput("bottom", c)
end
end
3 posts
Posted 14 April 2012 - 02:42 AM
you look for a redstone event? try this (and btw: you don't do "os.pullEvent" you use "os.pullEvent()")
while true do
event, side = os.pullEvent("redstone")
if rs.getInput("top") == true then
sleep(.2)
if rs.getInput("left") == true then
c = colors.combine(colors.green)
rs.setBundledOutput("bottom", c)
sleep(1)
c = colors.subtract(color.green)
rs.setBundledOutput("bottom", c)
sleep(1)
c = colors.combine(colors.orange)
rs.setBundledOutput("bottom", c)
sleep(1)
c = colors.combine(colors.green)
rs.setBundledOutput("bottom", c)
sleep(1)
c = colors.subtract(colors.green)
rs.setBundledOutput("bottom", c)
sleep(1)
c = colors.subtract(colors.orange)
rs.setBundledOutput("bottom", c)
sleep(1)
c = colors.combine(colors.brown)
rs.setBundledOutput("bottom", c)
sleep(1)
c = colors.combine(colors.orange)
rs.setBundledOutput("bottom", c)
end
else if rs.getInput("right") == true then
c = colors.subtract(colors.orange)
rs.setBundledOutput("bottom", c)
sleep(1)
c = colors.subtract(colors.brown)
rs.setBundledOutput("bottom", c)
sleep(1)
c = colors.combine(colors.grey)
rs.setBundledOutput("bottom", c)
sleep(1)
c = colors.subtract(colors.gray)
rs.setBundledOutput("bottom", c)
sleep(1)
c = colors.combine(colors.orange)
rs.setBundledOutput("bottom", c)
sleep(1)
c = colors.subtract(colors.orange)
rs.setBundledOutput("bottom", c)
sleep(1)
c = colors.combine(colors.green)
rs.setBundledOutput("bottom", c)
sleep(1)
c = colors.combine(colors.grey)
rs.setBundledOutput("bottom", c)
sleep(1)
c = colors.subtract(colors.grey)
rs.setBundledOutput("bottom", c)
sleep(1)
c = colors.subtract(colors.green)
rs.setBundledOutput("bottom", c)
sleep(1)
c = colors.combine(colors.gray)
rs.setBundledOutput("bottom", c)
sleep(1)
c = colors.subtract(colors.gray)
rs.setBundledOutput("bottom", c)
end
end
First and foremost, thank you much for your assistance. It's reassuring to know that I wasn't too far off as far as the coding is concerned. I implemented your revised code and the first thing I got was an "end" error, go figure at the end of the entire code. No biggie. After fixing that the program startsup smoothly but once I trigger it, I get maybe two steps in the piston sequence and then the program finds a fault. It says, "doorControl.lua:56: bad argument: int expected, got nil". I'm not entirely sure what that means :/
1111 posts
Location
Portland OR
Posted 14 April 2012 - 02:53 AM
Check this line
else if rs.getInput("right") == true then
should be elseif one word
474 posts
Posted 14 April 2012 - 03:15 AM
Check this line
else if rs.getInput("right") == true then
should be elseif one word
Actually, doesn't matter.
474 posts
Posted 14 April 2012 - 03:17 AM
First and foremost, thank you much for your assistance. It's reassuring to know that I wasn't too far off as far as the coding is concerned. I implemented your revised code and the first thing I got was an "end" error, go figure at the end of the entire code. No biggie. After fixing that the program startsup smoothly but once I trigger it, I get maybe two steps in the piston sequence and then the program finds a fault. It says, "doorControl.lua:56: bad argument: int expected, got nil". I'm not entirely sure what that means :/
Is it because you're using colors.
grey and colors.
gray?
1111 posts
Location
Portland OR
Posted 14 April 2012 - 03:18 AM
Check this line
else if rs.getInput("right") == true then
should be elseif one word
Actually, doesn't matter.
else if is the same as doing:
else
if
not elseif
else if runs the else statement then the if statement
elseif run the elseif statement
474 posts
Posted 14 April 2012 - 03:19 AM
Check this line
else if rs.getInput("right") == true then
should be elseif one word
Actually, doesn't matter.
else if is the same as doing:
else
if
not elseif
else if runs the else statement then the if statement
elseif run the elseif statement
Nope, both do the same for me.
1111 posts
Location
Portland OR
Posted 14 April 2012 - 03:19 AM
First and foremost, thank you much for your assistance. It's reassuring to know that I wasn't too far off as far as the coding is concerned. I implemented your revised code and the first thing I got was an "end" error, go figure at the end of the entire code. No biggie. After fixing that the program startsup smoothly but once I trigger it, I get maybe two steps in the piston sequence and then the program finds a fault. It says, "doorControl.lua:56: bad argument: int expected, got nil". I'm not entirely sure what that means :/
Is it because you're using colors.
grey and colors.
gray?
grey is for colours and gray is for colors. so the definitely could be the issue.
474 posts
Posted 14 April 2012 - 03:22 AM
First and foremost, thank you much for your assistance. It's reassuring to know that I wasn't too far off as far as the coding is concerned. I implemented your revised code and the first thing I got was an "end" error, go figure at the end of the entire code. No biggie. After fixing that the program startsup smoothly but once I trigger it, I get maybe two steps in the piston sequence and then the program finds a fault. It says, "doorControl.lua:56: bad argument: int expected, got nil". I'm not entirely sure what that means :/
Is it because you're using colors.
grey and colors.
gray?
grey is for colours and gray is for colors. so the definitely could be the issue.
Yeah, I thought that.
1111 posts
Location
Portland OR
Posted 14 April 2012 - 03:22 AM
Check this line
else if rs.getInput("right") == true then
should be elseif one word
Actually, doesn't matter.
else if is the same as doing:
else
if
not elseif
else if runs the else statement then the if statement
elseif run the elseif statement
Nope, both do the same for me.
Probably just fits in with your logic, they are kind of the same if you work it right, but else if ~= elseif
Try using more then 1 else if in an if statement
3 posts
Posted 14 April 2012 - 04:11 AM
Thank you all for puttin your heads together on this one. I changed the gray/grey issue and modified the else if statement and yet still, same error of nil result at line 56. Could anyone explain to me the technichal aspect of the error, so I may be able to better understand what's happening here?
474 posts
Posted 14 April 2012 - 04:16 AM
Thank you all for puttin your heads together on this one. I changed the gray/grey issue and modified the else if statement and yet still, same error of nil result at line 56. Could anyone explain to me the technichal aspect of the error, so I may be able to better understand what's happening here?
From the technical aspect, it's needs a number (
int), but it's getting *nothing* (
nil).
1111 posts
Location
Portland OR
Posted 14 April 2012 - 04:24 AM
try changing your colors statements to something like
c = colors.combine( c, colors.white )
You can even cleanup your code a little and combine all of the combines to one line, and the subtracts to one line like
c = colors.combine( c, colors.white, colors.black, colors.red ) -- and so on
Not sure if its the problem but might help. If we dont figure it out by the time I get home I will setup a small lab and try to duplicate/fix the issue.