You are not a noob since:
You tried to do it yourself first and posted the code.
You give a description of what you want to do.
Okay, that was the noob issue. Now the code.
You need to be more clear for yourself.
Hyd1 to 5 isn't very descriptive. Names as UpDownHyd ForwBackHyd are better to use.
Don't use the same variable name as input and output anyway.
How to fix it?
Just write down a simple list on what happens and what triggers it.
But you need to make sure that it is triggered on the right moment. A good way to achieve that is to use Fase or Stage variable. This one keeps everything working in the right order.
Code:
@name Automated Factory Grabber
@inputs Start RangerFront
@outputs LiftHyd ForwardHyd Grabber
@persist Fase First
interval(100)
if (!First) #This makes sure your hydraulics start at the right value when you spawn the gate
{
LiftHyd=50
ForwardHyd=10
Grabber=0
First=1
}
if (Start&Fase==0) #If the button is on it will continue processing the fases. Otherwise it just waits.
{
Fase=1
}
if (Fase==1)
{
LiftHyd-=1 #Every clk 1 is taken of the LiftHydr
if (Fase==1&LiftHyd<10) #Until is 10 or less, then it continues to fase 2
{
Fase=2
}
}
if (Fase==2)
{
ForwHyd+=1
if (Fase==2&RangerFront) #Stay in fase 2 until something hits the ranger. (Assuming you set it to default to zero)
{
Fase=3
}
}
if (Fase==3)
{
LiftHyd+=1
if (Fase==3 & LiftHyd>30) #When the lift hydraulic has extended to 30 or more then
{
Grabber=1 #Activate the grabber
Fase=0 #And return to the start of the program
}
}
Obviously this code is not complete, just to give you an idea.
I hope it helps!
@Lucas
A timer is a way to keep things in track, but it's very unreliable.
Whenever there is a slight problem everything is affected.
Bookmarks