-
Notifications
You must be signed in to change notification settings - Fork 100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Setting InkList variables #920
Comments
After spending 5 hours debugging the code, I found a convoluted way to update a global list. import { InkList, InkListItem } from "inkjs/engine/InkList";
import { ListValue } from "inkjs/engine/Value";
// 1. Create fake InkList
const myList = new InkList()
data.forEach((item) => {
myList.Add(new InkListItem("myList", item.strName), item.intValue);
});
// 2. Retrieve a copy of the existing ListValue
const listValue = ink.variablesState.GetVariableWithName(
"myList"
)! as ListValue;
// 3. Mutate the ListValue value with our new list
listValue.value = myList
// 4. Replace the global ListValue
ink.variablesState.SetGlobal("myList", listValue);
// 5. Get ink to use the new list when calling Continue
ink.variablesState.SnapshotDefaultGlobals(); |
Hi! Thanks for reporting this and a workaround too. I haven't touched inkjs in a while and probably won't for some more time, so I have no idea what could cause this at this point. If you want to provide a PR to fix the issue though I'd be happy to assist :) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Describe the bug
To Reproduce
Expected behavior
the ink story is updated with the global LIST variable
myList
and the new content added.Environment
Additional context
I'm trying to modify the initial value of a list in an ink story, and am failing to because of the error above. Wondering if this is due to the
Value.Create
internal call, when Value is an abstract class ?I'm having trouble to handle this InkList to InkObject conversion. What would be the appropriate way to replace an InkList variable with new content ?
As a side note, the type of
VariableState.$
should be updated to allow a single parameter for read access. Right now, I must callink.variablesState.$("myList", undefined)
if I want to read the content.The text was updated successfully, but these errors were encountered: