inkjs icon indicating copy to clipboard operation
inkjs copied to clipboard

Can't enumerate variables without accessing private attribute `_globalVariables`

Open drpepper opened this issue 9 months ago • 0 comments

Describe the bug

Hello! I'm new to ink and inkjs, but so far I'm loving it!

For my project, I would like to be able to list all variables and their values in order to see and modify them as the game plays.

I can access individual variables through the Story.variablesState proxy, but I haven't found a way to enumerate them.

Right now I'm using a hacky way to do it, by accessing the private attribute Story.variablesState._globalVariables directly, and ignoring the TypeScript error.

Is there a better way to do this? If not, what about adding [[OwnPropertyKeys]] to the proxy?

To Reproduce

Try to enumerate variables like: Object.keys(Story.variablesState).

Expected behavior

Object.keys(Story.variablesState) should provide an array of variables.

Environment

  • OS: macOs
  • Web browser version: Chrome 124
  • inkjs version: 2.2.2

Additional context

Thanks for your help!

drpepper avatar May 10 '24 12:05 drpepper