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 function without an if #49

Open
justjuank opened this issue Jun 6, 2019 · 2 comments
Open

Calling function without an if #49

justjuank opened this issue Jun 6, 2019 · 2 comments

Comments

@justjuank
Copy link

Hello,
I've been having an issue trying to pass correct typed values to a function from Yarn.
I'm a bit confused about the syntax so here's an example of what I'm trying to do:

<<set $exp = 50>>
You manage to capture [greenColor][rewardQuantity] [rewardName][/greenColor]!
<<AddPlayerStats("fishing",50)>>

(This doesn't work)

My registered function AddPlayerStats doesn't get called. But if I use the function with and if or a set, it gets called successfully, like this:

<<set $exp = 50>>
You manage to capture [greenColor][rewardQuantity] [rewardName][/greenColor]!
<<set $test = AddPlayerStats("fishing",50)>>

(This works)

If I make this function a command instead of a function, it will only pass text values, and I don't want to parse the 50 as a int in my code, I want to get it typed just like the way I get it when using a Yarn function.

Is this a limitation?

Also another issue I'm having is, if I try to pass a variable to the function like this:

<<set $exp = 50>>
You manage to capture [greenColor][rewardQuantity] [rewardName][/greenColor]!
<<set $test = AddPlayerStats("fishing",$exp)>>

(This doesn't work)

I get this error:
image

Any advice?
Thanks in advance.

Juan

@ghost
Copy link

ghost commented Sep 20, 2020

I see the same issue trying to call a command as shown here in the documentation (https://yarnspinner.dev/docs/unity/working-with-commands/). It doesn't do anything but yield a CommandResult.

runner.js line 137 yields a CommandResult object instead of evaluating the function. There isn't a very good workaround due to the fact that the arguments are not evaluated for expressions. The CommandResult object should at least have an array of evaluated arguments, so that we could invoke the registered function. Instead we are handed the raw parameters which could include unevaluated expressions. The raw parameters are also given as a single parameter if using parenthesis to call the function.
"myfunc($var1, 200, "test")
The resulting CommandResult has one parameter "($var1, 200, "test")".

I think a reasonable solution would be to add a few properties to CommandResult, name, args and result.
In the runner, run the function if it exists, capturing the result and then finally yield a CommandResult with added properties.
This allows the dev to implement their own function call handler, but also use the built-in one too.

Why allow for custom function handler? Because there might be a need for synchronous functionality and calling a function is async.

@ghost
Copy link

ghost commented Sep 20, 2020

After looking at this closer, the parser and lexer would also have to be modified, because currently they only seem to be able to parse functions with arguments within a conditional.

Also, nowhere in the documentation does it say that conditionals and assignments are to support function calls. So a function call can not be inside of an expression. This makes sense, because function calls do not require parenthesis encapsulating their arguments, making it ambiguous where the function call begins and ends. The spec would have to say, only function calls with arguments in parenthesis are allowed inside of an expression, and it doesn't say that anywhere. There is an exception though and that is the visited() function.

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

1 participant