Advertisement
Guest User

Untitled

a guest
Oct 13th, 2023
14
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.26 KB | Software | 0 0
  1. Sorry for the wordy title, please feel free to change it - I just don't know a better way to phrase it.
  2.  
  3. Harlowe version 3.3.7.
  4.  
  5. **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.
  6.  
  7. **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:
  8.  
  9. ```
  10. (set: $testMacro to (macro: ...string-type _arguments, [
  11. (set: _argumentCount to -1)
  12. (if: _arguments is an empty)[
  13. (set: _argumentCount to 0)
  14. ]
  15. (else:)[
  16. (set: _argumentCount to _arguments's length)
  17. ]
  18. (output:)[You provided (plural: _argumentCount, "argument")!]
  19. ]))
  20. ```
  21.  
  22. Calling this macro with any number of arguments works as expected.
  23.  
  24. ```
  25. ($testMacro: "test", "also test")
  26. ($testMacro: "test")
  27. ($testMacro:)
  28.  
  29. Produces:
  30.  
  31. You provided 2 arguments!
  32. You provided 1 argument!
  33. You provided 0 arguments!
  34. ```
  35.  
  36. 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:
  37.  
  38. ```
  39. (set: $testMacro to (macro: string-type _bob, ...string-type _arguments, [
  40. (set: _argumentCount to -1)
  41. (if: _arguments is an empty)[
  42. (set: _argumentCount to 0)
  43. ]
  44. (else:)[
  45. (set: _argumentCount to _arguments's length)
  46. ]
  47. (output:)[You provided (plural: _argumentCount, "argument")!]
  48. ]))
  49.  
  50. ($testMacro: "test", "also test")
  51. ($testMacro: "test")
  52. ```
  53.  
  54. 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:
  55.  
  56. ```
  57. 3 errors occurred when running a custom macro (with str-type _bob and ...str-type _arguments).
  58. ```
  59.  
  60. Checking the details, the three errors are:
  61.  
  62. ```
  63. There isn't a temp variable named _arguments in this place.
  64. There's nothing before this to do (else:) with.
  65. There isn't a temp variable named _arguments in this place.
  66. ```
  67.  
  68. 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.
  69.  
  70. 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:
  71.  
  72. ```
  73. 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
  74. So I think a bug report is correct, yes
  75. ```
  76.  
  77. Let me know if you need any other details!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement