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

Need help with redstone commands

Started by jordsta95, 15 October 2015 - 07:54 PM
jordsta95 #1
Posted 15 October 2015 - 09:54 PM
Hi there, so I have always used the built in stuff (e.g. excavate) as I never really needed to use CC for more than that. However, I want to do more advanced stuff, and CC is going to be best to automate this. So what I am trying to do is run the following code on button press:



redstone.setOutput("down", true)
sleep(0.05)
redstone.setOutput("down", false)
sleep(2)
redstone.setOutput("down", true)
sleep(0.05)
redstone.setOutput("down", false)
sleep(2)
redstone.setOutput("down", true)
sleep(0.05)
redstone.setOutput("down", false)
sleep(2)
redstone.setOutput("up", true)
sleep(0.05)
redstone.setOutput("up", false)
sleep(2)
redstone.setOutput("up", true)
sleep(0.05)
redstone.setOutput("up", false)
sleep(2)
redstone.setOutput("up", true)
sleep(0.05)
redstone.setOutput("up", false)
sleep(2)
redstone.setOutput("back", true)
sleep(1)
redstone.setOutput("right", true)
sleep(0.05)
redstone.setOutput("right", false)
sleep(2)
redstone.setOutput("back", false)
sleep(1)
And repeat that 3 more times, then do:

redstone.setOutput("left", true)
sleep(0.05)
redstone.setOutput("left", false)
sleep(2)
4 times. And that would be where it ends ready for the next button press (or other means of redstone activation) to begin the process again.


However, I feel I am doing something wrong, as I did just a few lines and when I saved the program it deleted it.
So I:
Opened the Advanced Computer
Typed:
edit quarry
Typed in the first 4 lines of the code I intend to use
Saved the program
And when I went to run it, it wasn't saved, and when I tried to edit it it was blank.
But that I can sort out at a later date, my main issue is getting the code correct.
Do I need to do anything like put "start" and "end" around the code? Is there anything missing from what I have shown that is needed?

Sorry if this sounds like I don't know what I'm doing.

Thanks
-Jordan
KingofGamesYami #2
Posted 16 October 2015 - 01:30 AM
Do I need to do anything like put "start" and "end" around the code? Is there anything missing from what I have shown that is needed?

No, just what you've got. Here's some helpful hints though:

1) rs is an alias for redstone. Meaning you don't need to type out redstone every single time, you can just use rs in place of it.
2) for loops are amazing for doing repetitive tasks (for i = 1, 3 do … end)
3) if you don't have anything else providing redstone to the turtle, you could simply do

os.pullEvent( "redstone" )
to wait for a button.
4) it sounds like you want it to repeat indefinately, always waiting for a redstone input after completing the task. For this, use an infinate loop (while true do … end).

Example Program:

while true do
  for i = 1, 3 do
    --#put your first code here
  end
  for i = 1, 4 do
    --#put your second code here
  end
  os.pullEvent( "redstone" )
end
Bomb Bloke #3
Posted 16 October 2015 - 06:23 AM
You can read up on for loops here.

Keep in mind that Minecraft only checks redstone states every tenth of a second. If you enable and then disable them any faster than that, it's unlikely they'll do anything.
jordsta95 #4
Posted 16 October 2015 - 08:52 AM
Do I need to do anything like put "start" and "end" around the code? Is there anything missing from what I have shown that is needed?

No, just what you've got. Here's some helpful hints though:

1) rs is an alias for redstone. Meaning you don't need to type out redstone every single time, you can just use rs in place of it.
2) for loops are amazing for doing repetitive tasks (for i = 1, 3 do … end)
3) if you don't have anything else providing redstone to the turtle, you could simply do

os.pullEvent( "redstone" )
to wait for a button.
4) it sounds like you want it to repeat indefinately, always waiting for a redstone input after completing the task. For this, use an infinate loop (while true do … end).

Example Program:

while true do
  for i = 1, 3 do
	--#put your first code here
  end
  for i = 1, 4 do
	--#put your second code here
  end
  os.pullEvent( "redstone" )
end
Thanks, I'll try that and probably come back trying when I break something :)/>

You can read up on for loops here.

Keep in mind that Minecraft only checks redstone states every tenth of a second. If you enable and then disable them any faster than that, it's unlikely they'll do anything.
Ah right. thanks. That should still be fine with 0.1 as it is just to pulse the redstone
jordsta95 #5
Posted 16 October 2015 - 09:59 AM
So I tried doing it as I typed in the OP, just so I could see it work, and the timings were off, so I extended the timings, yet it still gets confused: http://pastebin.com/n8sakDMX
It won't turn the signal on, wait, and turn off half a second later, then wait 5 seconds before going again.
Also it will activate bottom, then top, then bottom again, without activating the back or right
Bomb Bloke #6
Posted 16 October 2015 - 11:57 AM
It won't turn the signal on, wait, and turn off half a second later, then wait 5 seconds before going again.

You've got some "true"s where you want some "false"s.

Also it will activate bottom, then top, then bottom again, without activating the back or right

IIRC, when dealing with redstone, a computer's "right" is the side that's to your right when you're facing its screen. Compare this to a turtle, where its "right" is to your right when you're facing its rear. The "front"s and "back"s, however, should certainly be where you expect them to be.
jordsta95 #7
Posted 16 October 2015 - 11:57 AM
I then I realized that all the bottom's were set to true. So that's fixed, and it's working now :D/>

Ninja'd
Edited on 16 October 2015 - 09:58 AM