Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Sorry for the wordy title, please feel free to change it - I just don't know a better way to phrase it.
- Harlowe version 3.3.7.
- **Issue:** If you have a custom macro with two or more parameters, where the last parameter uses the spread syntax, then calling that macro with _no_ variable in the last parameter spot causes an error when it appears it should not.
- **Example:** Here's a simple custom macro that takes one parameter (`_arguments`), which uses the spread syntax. The macro basically counts the number of elements in the array created by the spread parameter syntax, and prints it out:
- ```
- (set: $testMacro to (macro: ...string-type _arguments, [
- (set: _argumentCount to -1)
- (if: _arguments is an empty)[
- (set: _argumentCount to 0)
- ]
- (else:)[
- (set: _argumentCount to _arguments's length)
- ]
- (output:)[You provided (plural: _argumentCount, "argument")!]
- ]))
- ```
- Calling this macro with any number of arguments works as expected.
- ```
- ($testMacro: "test", "also test")
- ($testMacro: "test")
- ($testMacro:)
- Produces:
- You provided 2 arguments!
- You provided 1 argument!
- You provided 0 arguments!
- ```
- So far so good. Now, if we modify the macro to simply add another argument (`_bob`) before the spread argument, the macro will suddenly produce an error when no variable is passed to the `_arguments` parameter spot:
- ```
- (set: $testMacro to (macro: string-type _bob, ...string-type _arguments, [
- (set: _argumentCount to -1)
- (if: _arguments is an empty)[
- (set: _argumentCount to 0)
- ]
- (else:)[
- (set: _argumentCount to _arguments's length)
- ]
- (output:)[You provided (plural: _argumentCount, "argument")!]
- ]))
- ($testMacro: "test", "also test")
- ($testMacro: "test")
- ```
- Here, the `"test"` string is taken by the `_bob` parameter. The first call to the custom macro successfully prints `You provided 1 argument!`. The second call (`($testMacro: "test")`) produces:
- ```
- 3 errors occurred when running a custom macro (with str-type _bob and ...str-type _arguments).
- ```
- Checking the details, the three errors are:
- ```
- There isn't a temp variable named _arguments in this place.
- There's nothing before this to do (else:) with.
- There isn't a temp variable named _arguments in this place.
- ```
- The docs don't suggest the above second macro shouldn't work. They say `A custom macro stored in $mean with ...num-type _n can be called [...] ($mean:)[, which] sets _n to (a:). Note that because it takes every value at or after it, it must be the final parameter of your custom macro.` The second custom macro example has the spread parameter as the final parameter of the macro definition, and from the docs calling the macro without a variable passed in that parameter slot is valid syntax and should produce an empty array - but it doesn't seem to when the spread parameter isn't the _only_ parameter.
- I asked about it in the Twine Games Discord server, and user `hituro` believes the root cause is in `js/datatypes/custommacro.js`, line `107`. They say:
- ```
- There's basically a special case there for an empty ... argument when there's no arguments to the macro, but it only applies when there isn't actually any other argument
- So I think a bug report is correct, yes
- ```
- Let me know if you need any other details!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement