Altered LISTs do not have origins set after LoadJson()
- Dominant language
- C#
- Stars
- 4.9k
- Forks
- 540
- PR merge metrics
- No merged PRs in 30d
Description
If I have a global `LIST`, e.g.:
```
LIST some_list = (none), step_one, step_two, completed
```
I can get this list from within Unity with:
```
Ink.Runtime.InkList unityList = story.variablesState["some_list"] as Ink.Runtime.InkList;
```
And when I do `unityList.origins`, it is populated and usable. I can also use `.all` and other properties that depend on `origins` being populated. All good so far.
If I then do `SaveJson()` and `LoadJson()` I can get the list from `variablesState` again, and `origins` is populated just like before. Still… all good.
_However_, if the Ink script has changed the value of `some_list` before the save, e.g.:
```
~ some_list = step_one
```
And then I `SaveJson()` and `LoadJson()`, when I get the list from `variablesState` this time, `.origins` is `null`.
`.origins` remains `null` until the Ink script encounters some code that evaluates this list. (It can be assigning a new value or just checking its contents.) Then `origins` gets populated once again.
From stepping through the Ink-runtime code, it looks like `StoryState::PushEvaluationStack(Runtime.Object obj)` is responsible for populating `origins` and I think this is where the problem lies.
When an Ink `Story` is first loaded from C#, `PushEvaluationStack` gets called on every global var, thus populating `origins` in all the lists. If you then do a `LoadJson()`, and the List value hasn't changed, this initial init is still valid and everything works. _But_, if the value has changed, it looks like the list is re-created(?) and this time, `PushEvaluationStack` does **not** get called (until it is used in some Ink code that is run later).
In summary, I think the problem in the Ink runtime might be:
1. `PushEvaluationStack` is called on all global Ink vars at the start.
2. After a `LoadJson()`, it looks like `LIST`s that no longer have their default value are re-created in memory.
3. But, `PushEvaluationStack` is not called on these, leaving them not fully initialized.
**UPDATE: I have opened a PR with a fix, which solves the problem I was having with this. But, I'm pretty sure it should be fixed in a more comprehensive way. Hopefully this PR is a useful start though: https://github.com/inkle/ink/pull/764**
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.