Is there anything more similar to a global variable than state?

I am creating a hidden text function in my template.Hide text by setting its color to match the background color.

#let theme_style = state("theme", "abyss") 

#let hidden-text(
  body
) = {
  text(fill: themes(theme: theme_style.at("theme"), setting: "background-color"))[#body] // 使用背景色填充文本 / Fill text with background color
}

The background color is set by defining a theme in the main function and retrieving the corresponding color.

#let twlight-book(
  // ...
  theme: "abyss"
  // ...
) = {
  // 全局化主题设置 / Globalize theme settings
  theme_style = theme
}

However, the following error occurred: text is not locatable

There is hide.

The title is answered in Is there anything more similar to a global variable than state? - #3 by bluss.

(Answering the question in the title: You can place metadata with custom data into the document and query for that metadata, that is often an alternative to using state. It depends on use case if it makes sense though.)

theme_style is a state (in the previous code snippet), and you update its value using theme_style.update(theme). Maybe this is related to the error you see? If not, maybe you have a stand alone example that shows the problem?