inkjs
inkjs copied to clipboard
Calling EvaluateFunction() on functions with multiple arguments crashes
Describe the bug
I am attempting to call
var rtn = story.EvaluateFunction('get_data', ['pendant', 'description'])
when calling this I get the following errors:
Error: RUNTIME ERROR: (Ink Pointer -> get_data.5 -- index 3): Can not call use == operation on String and List
ink-full.js:1 Uncaught Error: Expected external function evaluation to be complete. Stack trace: === THREAD 1/1 (current) ===
[TUNNEL]
at e.value (ink-full.js:1:195358)
at o.value (ink-full.js:1:223547)
at <anonymous>:1:17
using EvaluateFunction() to call other ink functions with fewer args works as expected the function in question also works when called from inside the ink.
To Reproduce
load the ink file with the following function
=== function get_data(item, property)
{item:
- pendant:
{property:
- item_name: ~ return "Silver Pendant"
- description: ~ return "It's so shiny, wow."
}
- pristine_package:
{property:
- item_name: ~ return "Pristine Package"
- description: ~ return "An expertly wrapped package about the size of a shoebox. It weighs about one pound."
}
}
assign window.story = story
in browser ink
open browser console and enter the following:
var rtn = story.EvaluateFunction('get_data', ['pendant', 'description'])
observe error.
Expected behavior
I expect to receive a string value back
Ink files
Environment
- OS: Chrome OS
- Web browser version: Chrome 114
- inklecate version: N/A
- inkjs version: 2.2.1
Additional context
We intend to use this function to display an inventory, therefore we have designed it to use a series of look ups to produce the correct strings when called for.
Your error seems to be unrelated with the number of arguments, but rather with it being called with strings as parameters and ink expecting a list item in the comparaison operator :
Can not call use == operation on String and List
Namely, you are writing
{item:
- pendant:
}
where item
is the argument or the function, where you are passing 'pendant'
and then comparing it with pendant
(which is probably a list item otherwise it would not be valid ink)
how can I call this function from javascript without strings? is there a way to communicate to EvaluateFunction the types of the values I'm passing?
made the following change:
I made the following change:
=== function get_data(item, property)
{item:
- "pendant":
{property:
- "item_name": ~ return "Silver Pendant"
- "description": ~ return "It's so shiny, wow."
}
- "pristine_package":
{property:
- "item_name": ~ return "Pristine Package"
- "description": ~ return "An expertly wrapped package about the size of a shoebox. It weighs about one pound."
}
}
now it works when called from javascript, but when i call get_data() internally from the ink file, i get a similar error. is there a way I can have a function that works both ways?
Those two discord messages may be helpful to you :
- https://discord.com/channels/329929050866843648/329929050866843648/1066047658503962736
- https://discord.com/channels/329929050866843648/329929390358265857/478490691945889792
(those answers are for C# but should also work in js/ts)