Contextual alternates issue

Hello, I’m having an issue whit contextual alternates. I’m currently working on a semi connected script font and some letters like the r, s and b have alternates. I made the code for the contextual alternates and it works mostly fine, except for when I’m joining them together (srs, rsr, rrr and sss)
The code is this:

sub [a b c d e f g h i j k l m n o p q t u v w x y z] r' by r.alt;
sub [a b c d e f g h i j k l m n o p q t u v w x y z] s' by s.alt;

sub r s' by s.alt;
sub s r' by r.alt;
sub r r' by r.alt;
sub s s' by s.alt;

When I try making srs, rsr, rrr and sss some portion of the text doesn’t work according to the script (as shown on the images below). For example, on the srs text, the glyphs appear as s r.alt s, when it’s supposed to be s r.alt s.alt;


Is there any ways to fix this issue?
Thanks.

Can you try:

sub [a b c d e f g h i j k l m n o p q r s t u v w x y z r.alt s.alt] [r s]' by [r.alt s.alt];

That worked great, thanks!
I now just need to figure out connectors and how to use them. Seems like something complicated depending on how many are needed.
Also, is there any way to write so that every time a word begins with a certain letter it uses the alt instead? For example, every word that starts with b uses the b.alt glyph instead of the b glyph. (Is it what’s in the features contextual alternates part 4 tutorial?)

Yes. That is exactly it.

It turns out on two specific letters, r and s I made my default glyph to be the medial glyph, when in fact the default glyph needs to be the .init variant. Is there any way to workaround that? I couldn’t find the suffix for medial glyphs on the tutorial so I could add it into the code
Because then the default glyph would be the same as the init variation, the medial glyph would be the correct one (with the medial suffix, if it exists) and the init variation would still be the same glyph.

The glyph names are not important in this case. You can use the glyphs named r and s for the initial case and then change them to different glyphs for other contexts.