It's pretty self-explanatory; just click on the flag and enter the variables
Scratch custom blocks can handle recursion! I don't know whether or not I should disable screen refresh; it looks really cool when you can see how it's made. I'll remix it with that, as well as some other changes.