Redstone Pen

Redstone Pen

6M Downloads

How do I set up a loop?

tangzixiang-hash opened this issue ยท 5 comments

commented

I'm using control_box, I carefully read the instruction interface, and github's documentation, I tried it for 2 hours yesterday and I don't know how to set it up, a code I want,
For example, when port B has an input signal, then port Y will output 20 tick true, then 20 tick false, and then 20 tick true. And so on and so forth.

commented

Hi,

the RLC works signal based, so you don't implement like in normal imperative languages. It's actually simpler.
Means, you don't have loops or code that can hang up. Instead, the whole code is executed in one tick, and the values of the variables remain, so you can re-use them in the next tick. Then you use timers, counters, edge detectors etc. This also gives the mod a possibility to optimize performance - if you have something changed every 20 ticks, you don't need to waste server CPU for 19 ticks, except an input port changes ;)

So, the simplest solution is to generate a pulse every 20 ticks. The Timed Intervals TIVx objects can do that for you, I use TIV1 here. Then you toggle Y with that one tick pulse (here P), and force it off with B (if B not on/true).

# Pulse every 20 ticks
# (1 tck on, 19 off)
P = TIV1(20)

# XOR toggles Y if pulse is on.
# AND forces Y off if B is off.   
Y = B and (Y xor P)

image

commented

Thanks, but I have a question, why don't I see the introduction of TIV on the official github documentation?

commented

Thanks, I just tried it and it works very well.
https://github.com/stfwi/rsgauges
As you can see, I just wanted to implement the interval timer feature in the above mod, e.g. interval Xtick, true, interval Ytick false, this kind of function, but I haven't known how to do it.

commented

Because in 1.20, this mod stopped updating.

commented

Aye, G&S had grown big, but was eventually too much maintenance - hopefully someone will take over or re-use the features in that mod. I'll try to keep the Pen mod small an maintainable - although interfacing Redstone is a challenge of a kind ;).

I added the TIVx documentation in the RLC readme. Cheers and ty again for reaching out that this was missing.