Hi all,
I’ve been trying to keep track of an array of objects within my document in a “state” variable. I use the end result of the state at the end of the document to create a table at the beginning of my document. (it’s for document referencing)
I’m running into the odd problem that the “final” keyword does not seem to return the final version of the array. In fact, as far as I can tell it returns an array that should have never existed anywhere in the code.
Minimum Viable Product code:
#context state("test_state",0).update((
"TEST_01": ("VAR_1", "VAR_02", "VAR_03"),
"TEST_02": ("VAR_4", "VAR_05", "VAR_06"),
"TEST_03": ("VAR_7", "VAR_08", "VAR_09"),
))
#let change_state(ref, num) = {
context{
let ts = state("test_state").get()
if(ts.at(ref).at(num) != "CHANGED"){
ts.at(ref).at(num) = "CHANGED"
}
state("test_state").update(ts)
[#ts]
}
}
FINAL:
#context state("test_state").final()
CHANGE 01 02
#change_state("TEST_01",2)
CHANGE 02 01
#change_state("TEST_02",1)
CHANGE 02 02
#change_state("TEST_02",2)
CHANGE 03 01
#change_state("TEST_03",0)
What I would expect is that the final print after “CHANGE 03 01” is the same as the “FINAL” print. Since the state of the test_state there is the final version of the state.
However as you can see in the screenshot below, for some reason the .final() state is a permutation of the matrix that does not match. In fact, this permutation of the table has never existed anywhere in the document…
Row 1 is modified in the first function call of change_state. So I don’t see how it’s possible that the “final” version has an unmodified row 1, whilst some of the other rows are modified… I’m not sure if this is a bug or me not understanding how state variables work.