inkjs icon indicating copy to clipboard operation
inkjs copied to clipboard

Calling EvaluateFunction() on functions with multiple arguments crashes

Open acolchagoff opened this issue 1 year ago • 5 comments

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

bug.zip

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.

acolchagoff avatar Jul 27 '23 03:07 acolchagoff

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)

smwhr avatar Jul 27 '23 12:07 smwhr

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?

acolchagoff avatar Jul 31 '23 18:07 acolchagoff

made the following change:

acolchagoff avatar Aug 03 '23 01:08 acolchagoff

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?

acolchagoff avatar Aug 03 '23 01:08 acolchagoff

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)

smwhr avatar Aug 05 '23 16:08 smwhr