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

Set a os.pullEvent - Event each 2 days

Started by gustavowizard, 18 June 2014 - 01:14 AM
gustavowizard #1
Posted 18 June 2014 - 03:14 AM
Hey guys, i got this program here workign fine, however, my crops need more time to grow than 1 day, the way its set now i will harvest at 18h of each day, i need to set this up to harvest each 2 days or more, so i can get more than just seeds :D/>

somehow i need to set the event to start the program each 2 days only, instead of everyday at 18:00 o clock


--os.pullEvent("redstone")
local alarm = os.setAlarm(18)
while true do
local evt, arg = os.pullEvent("alarm")
if arg == alarm then
turtle.dig()
turtle.turnLeft() --2
turtle.forward()
turtle.turnRight()
turtle.dig()
turtle.turnLeft() --3
turtle.forward()
turtle.turnRight()
turtle.dig()
turtle.turnLeft() --4
turtle.forward()
turtle.turnRight()
turtle.dig()
turtle.turnLeft() --5
turtle.forward()
turtle.turnRight()
turtle.dig()
turtle.turnLeft()  --6
turtle.forward()
turtle.turnRight()
turtle.dig()
turtle.turnLeft() --7
turtle.forward()
turtle.turnRight()
turtle.dig()
turtle.turnLeft() --8
turtle.forward()
turtle.turnRight()
turtle.dig()
turtle.turnLeft() --9
turtle.forward()
turtle.turnRight()
turtle.dig()
turtle.turnLeft() --10
turtle.forward()
turtle.turnRight()
turtle.dig()
turtle.turnLeft() --11
turtle.forward()
turtle.turnRight()
turtle.dig()
turtle.turnLeft() --12
turtle.forward()
turtle.turnRight()
turtle.dig()
turtle.turnLeft() --13
turtle.forward()
turtle.turnRight()
turtle.dig()
turtle.turnLeft()
turtle.forward()
turtle.turnRight()
turtle.dig()
turtle.select(1)
turtle.drop()
turtle.select(2)
turtle.drop()
turtle.select(3)
turtle.drop()
turtle.turnRight()
turtle.forward()
turtle.forward()
turtle.forward()
turtle.forward()
turtle.forward()
turtle.forward()
turtle.forward()
turtle.forward()
turtle.forward()
turtle.forward()
turtle.forward()
turtle.forward()
turtle.forward()
turtle.forward()
turtle.turnLeft()
else
end
end

http://pastebin.com/SKRVyWNv

nvm the 1 line btw
theoriginalbit #2
Posted 18 June 2014 - 03:17 AM
your easiest way would be just to count the number of times the alarm has gone off and only once it has gone off twice do you go and harvest the crops.
gustavowizard #3
Posted 18 June 2014 - 07:38 AM
your easiest way would be just to count the number of times the alarm has gone off and only once it has gone off twice do you go and harvest the crops.

i dont understand, how?
Cycomantis #4
Posted 18 June 2014 - 08:44 AM
Something like…

local alarmCount = 0
while true do
local alarm = os.setAlarm(18)
local evt, arg = os.pullEvent("alarm")
alarmCount = alarmCount + 1
if alarmCount == 2 then
alarmCount = 0
--run the program
end
end
Edited on 18 June 2014 - 06:45 AM
Lignum #5
Posted 18 June 2014 - 11:18 AM
You should also organise your code with the help of for loops.
Cavious #6
Posted 18 June 2014 - 09:14 PM
I agree,

Organizing and creating reusable code will save you and others an enormous amount of time. I am still finding ways to minimize my code, and make it reusable.

I'd suggest creating a function, and calling a loop such as:

x = 0
repeat
    myFunction()
until(x == 7)
--OR
while(x < 7) do
    myFunction()
end

Good Luck,

Donald R. Valverde (Cavious)
theoriginalbit #7
Posted 19 June 2014 - 03:25 AM
I agree,

Organizing and creating reusable code will save you and others an enormous amount of time. I am still finding ways to minimize my code, and make it reusable.

I'd suggest creating a function, and calling a loop such as:

x = 0
repeat
	myFunction()
until(x == 7)
--OR
while(x < 7) do
	myFunction()
end

Good Luck,

Donald R. Valverde (Cavious)
you never increment your x variable. for loops like this you're better using a for loop.


for i = 1, 7 do
  --# code
end
Cavious #8
Posted 19 June 2014 - 09:32 PM
I agree,

Organizing and creating reusable code will save you and others an enormous amount of time. I am still finding ways to minimize my code, and make it reusable.

I'd suggest creating a function, and calling a loop such as:

x = 0
repeat
	myFunction()
until(x == 7)
--OR
while(x < 7) do
	myFunction()
end

Good Luck,

Donald R. Valverde (Cavious)
you never increment your x variable. for loops like this you're better using a for loop.


for i = 1, 7 do
  --# code
end

Of course, it was a mere example. I also never declared my function to exist. My point is "use a loop", since his program is suppose to persist for longer then what a for loop can do, its reasonable to suggest a "while loop", just with an incremental inside or an infinite with os.sleep() or even better a combo of loops within loops to provide him what he desires.
theoriginalbit #9
Posted 20 June 2014 - 05:36 AM
Of course, it was a mere example. I also never declared my function to exist. My point is "use a loop", since his program is suppose to persist for longer then what a for loop can do, its reasonable to suggest a "while loop", just with an incremental inside or an infinite with os.sleep() or even better a combo of loops within loops to provide him what he desires.
well if an infinitely loop was what you were aiming to provide an example for then this is better

while true do
  --# code
end

repeat
  --#code
until false