[Bug]: The return function outputs its return value to the chat

Open
#5,965 4 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Quiet
Tech stack
java
Domain
backend

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

bug
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

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from RPTools/maptool

All issues in RPTools/maptool

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.