Firstly, it may not be id'ing them correctly from left to right..
if you leave "order by: " blank, then I assume it will pick them based on the order they were created within the layout editor.
so either make a system that creates the chain objects on startup inbetween 'Red' and 'wall', or for now you can simply do "order by chain.x ascending", this will pick them from left to right.. (so bare in mind that this wont work if you want the chain to go in other directions)
next there are some picking problems with chain and link..
Im not sure if you just followed example, or you figured out for yourself, but the reason it's good to use a family here is to help make it clear what instances your action is referring to.
For example having "chain: create joint to chain" will make it confused as to what chains to pick
but having "chain: create joint to link" means that, in the conditions, you can specify what chain, and specify what link. Even though a link is just a chain, it allows you to pick two seperate chains. It's awkward, yes :)
link: id ? 3
chain: id ? 3
and for the last two events you just need to be consistent with whether your choosing link or chain.
the "link:id=0" event i think is fine, but the "link:id=3" event then goes on to refer to a chain instead.
for simplicity and ease of reading the sheet i'd replace all occurences of 'link' in those last two events with 'chain' instead