User @gabe gave a good summary about how state works, and the situation for counter is the same:
(Emphasis mine) The problem why your code doesn’t work is that, due to the explicit return, the update
is not put into the content of your document. Basically, there are two ways how a function’s return value may form:
- if the function reaches a
return
, the value of that statement is returned - otherwise, all values that were encountered are “joined”. For example, a function with body
{ [foo]; [bar] }
has as its result[foo]+[bar] = [foobar]
.
For the update to do anything, your result would need to include the update()
content, and that update content needs to end up in the document.
In your case, a fix that doesn’t interfere with the structure of your code too much would be to return the update and the array, so that your function would be called like this:
#let (update, questions) = mainFormatQuestions(myArray)
#update
#table(columns: (1fr, 1fr, 1fr),
inset: 10pt,
align: left,
..questions
)
Another option would be to do the whole table, not just constructing the array:
#questions-table(myArray)
Since questions-table()
returns content
and not an array, you could include the initial update in there.