#Can someone help me understand how to create a loop?

1 messages · Page 1 of 1 (latest)

vivid patio
#

I basically want to learn how to create a loop of 5s, 20s, whatever the value, and i want to test it on running the light on/off every x amount of seconds

noble abyss
#

you want a constant combinator with T=1, and a decider with "If t<60 output T input count". wire the constant to both the front and back of the decider and you're done, it will gain 1 T every game tick and reset back to 0 once per second. for a 2 or 20 second loop, just replace the 60 in the decider by 120 or 1200.

vivid patio
noble abyss
#

the reason this works is, combinators take 1 game tick to process their inputs. the decider reads T=1 from the constant combinator, and since T<60 it outputs T=1 one tick later.
then it reads T=1 from itself, plus T=1 from the constant, and outputs T=2. and on the next tick it reads T=3, and so on, +1 each tick until it outputs T=59. then it reads T=60, and since 60 is not less than 60 it outputs nothing and resets to 0

vivid patio
#

It is working actually, im just curious to understand them better, for example right now it flickers off very quickly, how do i go by creating a loop that will turn off 1 second, turn on 1 second...

noble abyss
#

well right now the T signal is looping from 1 to 60, so the lamp could be on when T<30 to flash evenly

#

or you could change the limit in the decider so T resets when it reaches 600 instead of 60, for a 10 second loop

vivid patio
#

So the combinators game clock is same as in real life 1 second ticks?

#

The value i set on the decider is in miliseconds i guess, so if i put it to 120, and then use the value on flashlight to T<60, i get 1 second off/ 1 second on

#

i think im getting it slowly, thank you xD @noble abyss

royal sleet
#

You can also use an arithmetic combinator with "<signal> modulo <duration>" instead of the Decider

modern iron