Skip to content
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

Calling EvaluateFunction() on functions with multiple arguments crashes #1020

Closed
acolchagoff opened this issue Jul 27, 2023 · 5 comments
Closed

Comments

@acolchagoff
Copy link

acolchagoff commented Jul 27, 2023

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.

@smwhr
Copy link
Collaborator

smwhr commented Jul 27, 2023

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)

@acolchagoff
Copy link
Author

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
Copy link
Author

made the following change:

@acolchagoff
Copy link
Author

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?

@smwhr smwhr changed the title Calling EvaluateFunciton() on funcitons with multiple arguments crashes Calling EvaluateFunction() on funcitons with multiple arguments crashes Aug 5, 2023
@smwhr smwhr changed the title Calling EvaluateFunction() on funcitons with multiple arguments crashes Calling EvaluateFunction() on functions with multiple arguments crashes Aug 5, 2023
@smwhr
Copy link
Collaborator

smwhr commented Aug 5, 2023

Those two discord messages may be helpful to you :

(those answers are for C# but should also work in js/ts)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants