How to correctly use state for an ordered outline?

Hello. I can’t compile a document that uses your function. See https://sscce.org.