[Bug]: The return function outputs its return value to the chat
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 45/100
Research direction
Start by tracing how macro execution handles return() and the h roll option, using the reproduction in the issue: a macro calls test_return@Lib:Test, whose code block returns a JSON value. Compare the output when h is on the code block with the expected silent behavior described in the issue. Done means the return value is returned without being printed to chat, and the issue’s reproduction no longer shows it there.
Written by the indexing model from the issue text.
Description
Describe the Bug
Specifying a return value causes that value to output in the chat. This can be avoided if you use the roll option h when you call the macro itself, but it cannot be avoided by putting the return function inside a code block that uses the h roll option. So, for example, [h,if(1), code: {[return(0, someData)]}] (or, alternatively, [h:return(0,SomeData)] )will output whatever someData is into the chat. There is certainly no reason I can tell from the documentation why the h roll option would work if and only if used when calling the macro, but not anywhere inside the macro.
To Reproduce
For problem 1:
Create two macros on a library token, let's call it Lib:Test. The first macro is called test, the second called test_return.
Then, inside test, type:
[macro("test_return@Lib:Test"):""]
Inside test_return, type:
[h,if(1), code: {
[returnData=json.set("{}",
"one", 1,
"two", 2,
"msg", "test complete"
)]
[macro.return=returnData]
[return(0,macro.return)]
}]
You will see {"one":1,"two":2,"msg":"test complete"} output in the chat.
Expected Behaviour
I would not expect the return value specified in argument 2 of return() to output in the chat, since the documentation does not mention this. And even so, I would expect the h roll option used on the code block would silence the output. Rather, I would expect it to do the same thing as if I replaced the function with [h:macro.return = "whatever"], which doesn't output even if the macro is not called with the h roll option.
Screenshots
No response
MapTool Info
1.18.6
Desktop
Windows
Additional Context
The only function I know of that isn't silenced by h, is assert(), but assert() isn't even silenced if the calling macro is prefaced by the h roll option. Given the lack of a continue keyword/function, it doesn't seem to me like our only early return function should do this.
- Dominant language
- Java
- Stars
- 927
- Forks
- 286
- Avg merge
- 3d 17h
- Merged PRs (30d)
- 94
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from RPTools/maptool
-
[Bug]: An initiative list with no current entry logs an error on every changePossibly taken @dwizard0 claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Maintainers usually reply within 1 day
-
[Maintenance]: Migrate gradle dependency submission to modern alternativePossibly taken @VelpulaGangavardhan claimed this 18 days ago. Opencode-maintenance
Difficulty 2/5 1-3 hours Newbie friendliness 77/100
RPTools/maptool#6156 · 2 comments · 1 assignee ·
Maintainers usually reply within 1 day
-
code-maintenance
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
Maintainers usually reply within 1 day
-
feature
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Maintainers usually reply within 1 day
Similar issues
-
Cleanup: restore the interrupt flag in AiFailureAnalyzerPossibly taken @Rishankgupta08 claimed this today. Opengood first issue
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
seleniumboot/selenium-boot#258 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100
johanhaleby/occurrent#1505 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
FasterXML/jackson-databind#6443 ·
Maintainers usually reply within 1 day
-
Docs: 2 broken linksOpen
Difficulty 1/5 Under an hour Newbie friendliness 78/100
Maintainers usually reply within 1 day