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

Frame Quarry Computer Control Help?

Started by toastedstapler, 28 December 2012 - 07:12 AM
toastedstapler #1
Posted 28 December 2012 - 08:12 AM
Hi.

So i have Redpower and Computercraft on my Minecraft and i am trying to get it so i can use a computer to control the quarries functions. My only problem is that i have to let it go down 5 blocks, then pause for a while to let the frame motor re-power. So have to let it go down 5 blocks, pause, then go again for 5 blocks, repeating the process 13 times in total. i have tried all sorts to get it to work, such as having a variable going up to a count of 5, then when it reaches 5 it counts up one on another variable and resets its self. When the second variable reaches 13 it stops the program. That is what I am aiming to do, but i cannot get it to work at all. Any help would be appreciated.

Thanks.
kornichen #2
Posted 28 December 2012 - 08:29 AM
Do it like this:


side = "right" -- Side of redstone
seconds = "5" -- seconds of pause
times = "13" -- times of repeating

while true do
redstone.setOutput(side, true)
sleep(seconds)
redstone.setOutput(side, false)
if times == 13 then
    break
end
times = times + 1
end
remiX #3
Posted 28 December 2012 - 08:58 AM
Do it like this:


side = "right" -- Side of redstone
seconds = "5" -- seconds of pause
times = "13" -- times of repeating

while true do
redstone.setOutput(side, true)
sleep(seconds)
redstone.setOutput(side, false)
if times == 13 then
	break
end
times = times + 1
end

Will not work because you made times a string, not a numerical value.


side = "right"
pauseTime = 5
nTimes = 13

for i = 1, nTimes do
    rs.setOutput(side, true)
    sleep(pauseTime)
    rs.setOutput(side, false)
    sleep(pauseTime)
end
kornichen #4
Posted 28 December 2012 - 09:17 AM
Do it like this:


side = "right" -- Side of redstone
seconds = "5" -- seconds of pause
times = "13" -- times of repeating

while true do
redstone.setOutput(side, true)
sleep(seconds)
redstone.setOutput(side, false)
if times == 13 then
	break
end
times = times + 1
end

Will not work because you made times a string, not a numerical value.


side = "right"
pauseTime = 5
nTimes = 13

for i = 1, nTimes do
	rs.setOutput(side, true)
	sleep(pauseTime)
	rs.setOutput(side, false)
	sleep(pauseTime)
end


Yes - I made a mistake … embarrassing *cough* shit *cough* ;)/>
toastedstapler #5
Posted 28 December 2012 - 12:41 PM
No, you made a mistake in understanding what i would like. It want it to move like this:

Down one block
Down another
Down another
Down another
Down another
Pause for 5 seconds so the motors can re-power
Down one block
and so on.

I need the pause to happen 13 times then stop, as i am digging 65 blocks down.
Hope this clears things a little.
AngelMalus #6
Posted 29 December 2012 - 02:00 AM
I can understand the frustration, but the thing is that you have to take a different approach to your coding.

Just need to put a 1 line condition inside the loop. If the loop has gone 5 times then Sleep(5)

The secret is on an arithmetic function
a - math.floor( a/b ) * b
That will return the reminder of a division. math.floor removes the decimals from any number.
But in LUA this can also be achieved with a%b



--[[
The time FrameMotors need to move a block is 0.8, so I am using 0.4 on the moving timer.
--]]

side = "right"
pauseTime = 5  -- The seconds to stop
pauseEvery = 5 -- The steps that will take without stop
blockCount = 65 -- 13x5 I believe is the number of blocks you want to move. So just use the total moving blocks down.

for i = 1, blockCount do
		rs.setOutput(side, true)
		sleep(0.4) -- thats usually the minimum time of movement.
		rs.setOutput(side, false)
		sleep(0.4)  -- Time is actually 0.8 so I separated in 2
--[[
And here is the tricky part, this is a MOD OPERATOR sign.
It divides a variable and returns the remaining after integers.
Ej, 3%5 will return 3, 5%5 wil return 0, 6%5 will return 1, 7%5 will return 2,
but 10 %5 will return 0. So any number that is exactly divided by 5
will return 0 reminder. This will force the code
to pause every 5 turns.
--]]
  if i%pauseEvery==0 then sleep(pauseTime) end
end



It looks scary only because the comments, here is without comments:


side = "right"
pauseTime = 5
pauseEvery = 5
blockCount = 65

for i = 1, blockCount do

   rs.setOutput(side, true)
   sleep(0.4)
   rs.setOutput(side, false)
   sleep(0.4)

  if i%pauseEvery==0 then sleep(pauseTime) end

end

Let me know if it works for you.

Cheers :ph34r:/>


P.S. Now if for any reason you really really really need to have the 13 and the 5 moving down separate, you can also put a "FOR" inside another "FOR".


for i=1,13 do -- This will repeat 13 times
	 for j=1,5 do -- This will move the frame exactly 5 times
		 rs.setOutput(side, true)
		 sleep(0.4)
		 rs.setOutput(side, false)
		 sleep(0.4)
	 end -- After finishing the 5 times
	 sleep(5) -- It will sleep for 5 seconds and continue the "i" loop 13 times
end

I like the first code better because if you need to move your quarry up and down, or dig less depth, you can just change the exact number of blocks, and it will be sure to stop every 5 blocks. On the second code, the program will not be able to move the Quarry only 17 blocks per say. Only multiples of 5.