Counter swapping

This guide, as all other counter computing/efficiency guides, aims to make block code almost obsolete using counters.

Concept

I will have a system, call it system S. This system will contain counters A and B, both of which I wish to swap their values. What do I mean by this? I want A to become B, and B to become A. How will we do this?

Practice

  1. Place down a trigger(call it N). This trigger will start our entire system. Make it transmit on channel “start swap”.
  2. Place down another trigger(call it M). M will trigger and activate on channel “start swap”, and will broadcast on “trigger a”. It will also trigger on “trigger a”.
  3. Counter A(mentioned in concept) will decrease on “trigger a”, and will have a target of 0. Counter C will increase on “trigger a”, and will have a target of 0.
  4. When A reaches target → M deactivates. Use a channel for this, “target = A”, and have a third trigger(call it L) that will trigger on “target = A” and activate on that channel.
  5. Have trigger L increment A and decrement B(mentioned in concept). Have L be recursive using channel “trigger b”.
  6. B will have a target of 0, when reached, deactivate L. Use channel “target = B”.
  7. K should increment counter B and decrement C. K will broadcast on “trigger c” and receive on “trigger c”.
  8. On target reached by C → deactivate K. Use channel “target = C”.

Finish

I may have made mistakes in explaining that, so if I did, please let me know! Thanks!

6 Likes

Ok hang on I’m lazy is this more memory efficient than block code?

Yes. Consumption: 235g’s(3 counters = 75g’s, 4 triggers = 160g’s, 75 + 160 = 235).

Well, if this really can work properly, this is insane. ~0.25% memory saved per code block

1 Like

This kind of makes sense.

So what I’m getting from this is that there’s a trigger loop running for each counter that flows into the other. The trigger loop stops when the counter is 0.

My main question would be: What would you need to do if you wanted to have a set target value for the counters A and B? Would you use another counter?

This is mainly to swap the values. If you want counter A and B to some number specific, you’d add two counters with the values to swap to. (I’m not sure if I understood what you meant)

@VALUEX, I did some testing and I figured out this could be done with only three triggers.
The triggers have to loop themselves and then the counters have to broadcast from trigger to trigger until the entire thing is done.

1 Like

So you have two triggers for the system and 1 to start the system or three for the system(swapping) itself?

All three are for swapping.

Oh, ok. I had originally theorized the idea like that, but I added an extra trigger to add a way to control the system. It’s optional though.

Also, do you have a problem with the counter maximum of 300? I’m referring to the loop breaker in case of a trigger loop going off forever.

Yes, but it can be fixed by adding a 0.015s delay(I believe).