add a random / unique number combinator

Post your ideas and suggestions how to improve the game.

Moderator: ickputzdirwech

mrvn
Smart Inserter
Smart Inserter
Posts: 5969
Joined: Mon Sep 05, 2016 9:10 am
Contact:

Re: add a random / unique number combinator

Post by mrvn »

This won't work with blueprints containing 2 random IDS then because they will build at the same time. Also when blueprinting the ID generator might be build first and only later the connection to the main circuit network appears or is build and then you get duplicates.

So very much not a solution.
Qon
Smart Inserter
Smart Inserter
Posts: 2164
Joined: Thu Mar 17, 2016 6:27 am
Contact:

Re: add a random / unique number combinator

Post by Qon »

mrvn wrote: Mon May 06, 2019 9:53 am This won't work with blueprints containing 2 random IDS then because they will build at the same time
Why would a blueprint need 2 ids?
And the IDs aren't random, they are sequential. So guaranteed to be unique.

Just generate one and reserve 2 and give the second to the other part that needs a separate ID. You can increase the counter by two by just having the constant combinator output 2 instead of 1.
mrvn wrote: Mon May 06, 2019 9:53 am Also when blueprinting the ID generator might be build first and only later the connection to the main circuit network appears or is build and then you get duplicates.
No. If the ID generator is built before the network connection it will not take an ID. It will never take ID 1.
Qon wrote: Fri May 03, 2019 11:51 pm To only save this count once, when the unit is built, the ID (I) should be written to on the conditions:
  • ID is 0
  • constant C combinator sends 1 to increment the count (by reading it with other the cable colour)
  • Connected to the main network (C > 1)
If you try to generate 2 at once like suggested above then you just have to do some trivial fix (change I > 0 to I > 1 in one decider) so that it will never take ID 2 either.
mrvn wrote: Mon May 06, 2019 9:53 am So very much not a solution.
You didn't try it. It's perfect. It was made by me, Qon the Infallible God. Didn't you read the name of the poster? ;)

It does rely on the ID generators being created sequentially and never removed. But the second one can be designed away fairly easily. So I did.
Here's an updated version that also contains a part that can detect when a unit is removed and then restores the count and is also a bit smaller. (It also uses I instead of C to to count units on the wire)

With the controller that makes sure the count cant decrease the rules are simply that only 1 deconstruction or construction of ID generators at once.
I'm considering having the count completely in the controller part so deconstruction can never interfere with the network-wide ID counter.
My mods: Capsule Ammo | HandyHands - Automatic handcrafting | ChunkyChunks - Configurable Gridlines
Some other creations: Combinassembly Language GitHub w instructions and link to run it in your browser | 0~drain Laser
mrvn
Smart Inserter
Smart Inserter
Posts: 5969
Joined: Mon Sep 05, 2016 9:10 am
Contact:

Re: add a random / unique number combinator

Post by mrvn »

Deconstruction is a big requirement for many people. Also consider what happens when circuit networks are split or joint. Still sounds like that is a problem because cutting the network would be like destroying all the unique number combinators on one side instantly.

As to why I would blueprint 2 at the same time? I might blueprint one and a minute later blueprint the other and the way the bots fly they fget connected at the same tick.

Or I build 1 of them weeks ago. Then I needed twice the factory so I copy&paste it. Now I need twice the factory again so I copy&paste it again.
Qon
Smart Inserter
Smart Inserter
Posts: 2164
Joined: Thu Mar 17, 2016 6:27 am
Contact:

Re: add a random / unique number combinator

Post by Qon »

mrvn wrote: Mon May 06, 2019 12:12 pm Deconstruction is a big requirement for many people.
Which is solved. As long as the network stays connected there's no problem. Actually, as long as you don't construct any new ID generators on that disconnected part before you merge them again you are free to disconnect and merge as you feel like. The requirement is that any new ID generators must be connected to the network sequentially. You can't merge in more than 1 (unassigned) ID generators at a time.
mrvn wrote: Mon May 06, 2019 12:12 pm Also consider what happens when circuit networks are split or joint. Still sounds like that is a problem because cutting the network would be like destroying all the unique number combinators on one side instantly.
They remember their ID and will not be destroyed. The connectedness of the network is just a requirement while building new ID generators so that they don't take a previously assigned ID on that other network they join. You are also free to split networks if you don't plan to join them again. The ID generators take an ID that no one else has on that network when they are built (or connected to main) and stores it permanently.

If networks are merged then the problem is that unique IDs on each network might not be unique in the merged network. But anything that has an ID number is completely unaffected by splits or merges.
mrvn wrote: Mon May 06, 2019 12:12 pm As to why I would blueprint 2 at the same time? I might blueprint one and a minute later blueprint the other and the way the bots fly they fget connected at the same tick.

Or I build 1 of them weeks ago. Then I needed twice the factory so I copy&paste it. Now I need twice the factory again so I copy&paste it again.
That's harder to solve. Might be impossible. But you could just go around and shoot (destroys it and the bots will place a ghost with invalid ID 0 so it will get reassigned) the ID memory cell of any duplicated ID to re-generate the IDs to new and unique ones. It's some manual work but if you are copying a factory with a handful of ID generators in them then it's not a big problem. Basically shoot the memory cell to reassign the ID to something unique on that network in case of any problems q:

Since I'm planning to use it for my recursive blueprint factory it isn't a concern there since I can build the ID generators sequentially and it still only takes a few seconds to copy an area with thousand ID generators.
My mods: Capsule Ammo | HandyHands - Automatic handcrafting | ChunkyChunks - Configurable Gridlines
Some other creations: Combinassembly Language GitHub w instructions and link to run it in your browser | 0~drain Laser
mrvn
Smart Inserter
Smart Inserter
Posts: 5969
Joined: Mon Sep 05, 2016 9:10 am
Contact:

Re: add a random / unique number combinator

Post by mrvn »

The copied memory cell will start of empty when placed. The combinator contents are not part of a blueprint. So that isn't a problem. The problem is that you can't be sure 2 ID generators connect to the network at the same time.

As you said you can detect duplicate IDs but then how do you make one of them generate a new one? That's something you can't solve without having a unique or random number. Which I why the whole suggestion exists.

I think the idea to use train IDs is the way to go for now. Just needs a little mod support to switch the train to automatic after being placed.The mod could have unique number combinator that actually is a 2x2m rail with a train stop and a train all rolled into one.
Qon
Smart Inserter
Smart Inserter
Posts: 2164
Joined: Thu Mar 17, 2016 6:27 am
Contact:

Re: add a random / unique number combinator

Post by Qon »

mrvn wrote: Mon May 06, 2019 12:47 pm The copied memory cell will start of empty when placed. The combinator contents are not part of a blueprint. So that isn't a problem. The problem is that you can't be sure 2 ID generators connect to the network at the same time.

As you said you can detect duplicate IDs but then how do you make one of them generate a new one? That's something you can't solve without having a unique or random number. Which I why the whole suggestion exists.
Yes, the point was that if they do connect at the same time and get a ID collision you can manually shoot the memory cell decider combinator (leftmost one in the new BP) to reset it, one at a time. That's manual work though which would be nice if you could avoid. But you can't automate artillery to destroy your memory cell on collision without a mod at the moment and no other way to do it either so it's not really easy to solve automatically.
mrvn wrote: Mon May 06, 2019 12:47 pm I think the idea to use train IDs is the way to go for now. Just needs a little mod support to switch the train to automatic after being placed.The mod could have unique number combinator that actually is a 2x2m rail with a train stop and a train all rolled into one.
You need either a mod that switches trains to automatic when placed or a mod that generates a UniqueSignal. There's no need for both if what you are after is just unique IDs since a mod can keep a global counter without relying on trains. But if they are switched to automatic then with such a blueprint you could also get a unique ID, yes.

Edit: I will probably make that train auto-auto mode mod. Shouldn't take too long.
My mods: Capsule Ammo | HandyHands - Automatic handcrafting | ChunkyChunks - Configurable Gridlines
Some other creations: Combinassembly Language GitHub w instructions and link to run it in your browser | 0~drain Laser
Qon
Smart Inserter
Smart Inserter
Posts: 2164
Joined: Thu Mar 17, 2016 6:27 am
Contact:

Re: add a random / unique number combinator

Post by Qon »

Once I'm sure I don't feel like changing the name I'll upload it to the portal. But here's a sneak peek. (Mod portal edition will also be 1.0.0 even if something changes)

It makes trains placed by bots start in automatic mode (once they have been completely built). Works on straight rails only because that's simpler.
So now you can make ID generators with this simple blueprint:

and scale your train force automatically with 'Recursive Blueprints' mod.

It's a tiny mod that only does a small check in the event on_train_created so its performance impact is absolutely minimal.

But it's a mod so it's not a vanilla feature. But it's just a tiny QoL fix so it's just a question of time before Wube will add this to vanilla.

Edit: mod attachment removed. The mod now exists on the portal. Do Robots Build Automatic Trains?
My mods: Capsule Ammo | HandyHands - Automatic handcrafting | ChunkyChunks - Configurable Gridlines
Some other creations: Combinassembly Language GitHub w instructions and link to run it in your browser | 0~drain Laser
Post Reply

Return to “Ideas and Suggestions”