y-lohse / inkjs

A javascript port of inkle's ink scripting language.
http://www.inklestudios.com/ink/
MIT License
489 stars 100 forks source link

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

Open drpepper opened 1 month ago

drpepper commented 1 month ago

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

Additional context

Thanks for your help!