1.8.4 Bug: return(a, b) evaluates macro.return if set to 1

Thoughts, Help, Feature Requests, Bug Reports, Developing code for...

Moderators: dorpond, trevor, Azhrei

Forum rules
PLEASE don't post images of your entire desktop, attach entire campaign files when only a single file is needed, or generally act in some other anti-social behavior. :)
Post Reply
SherbanWisperwald
Kobold
Posts: 3
Joined: Mon Dec 28, 2020 7:48 am

1.8.4 Bug: return(a, b) evaluates macro.return if set to 1

Post by SherbanWisperwald »

The following code snippet aborts with "must not happen" but should not:

Code: Select all

[h: macro.return = 1]
[h: return(0, "true found")]
[h: assert(0, "must not happen")]
Replacing the first line with

Code: Select all

[h: macro.return = 0]
or

Code: Select all

[h: macro.return = 2]
or

Code: Select all

[h: macro.return = "anything not == 1"]
works as I expect, i.e not showing any output in this short sample, or returning "true found" if called by another macro.

This is not real code, but a boiled down sample of minimum lines to show the error.

1.8.3 works as I expected.

Has anybody else encountered this behavior or can confirm, that this is a bug?

User avatar
aliasmask
RPTools Team
Posts: 9024
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: 1.8.4 Bug: return(a, b) evaluates macro.return if set to 1

Post by aliasmask »

Interesting. Yeah, probably shouldn't behave like that. One thing I do is try to only use one macro.return in my function and return() is also setting that value. So, if I were to write this code I would do it like this

Code: Select all

[h: return(errorCondition1, "something specific to this error")]
<!-- no errors, so do normal return -->
[h: macro.return = 1]
You should file a github issue, but in the meantime, just avoid putting a value in macro.return until the end of your code.

SherbanWisperwald
Kobold
Posts: 3
Joined: Mon Dec 28, 2020 7:48 am

Re: 1.8.4 Bug: return(a, b) evaluates macro.return if set to 1

Post by SherbanWisperwald »

Thanks for your response, I will file a bug for this.

I don't normally assign something to "macro.return" multiple times, this was just the shortest possible example I could imagine. The "production code" which was affected by the error is this:

Code: Select all

[h: '<!-- ==== void switchToCurrent() ==== -->']
[h, if(she_isDebug()): she_debug(getMacroName())]

[h: currentKey = "activeName_" + getPlayerName()]

[h: "<!-- check Library -->"]
[h: selected = getLibProperty(currentKey, "Lib:sheSettings")]
[h, if(she_hasTokenRights(selected)), code: {
    [switchToken(selected)]
    [return(0, 0)]
};{}]

[h: "<!-- check Impersonated -->"]
[h: selected = getImpersonated()]
[h, if(she_hasTokenRights(selected)), code: {
    [switchToken(selected)]
    [setLibProperty(currentKey, selected, "Lib:sheSettings")]
    [return(0, 0)]
};{}]

[h: "<!-- check Selected -->"]
[h: selected = getSelected()]
[h, if(listCount(selected) == 1 && she_hasTokenRights(selected)), code: {
    [switchToken(selected)]
    [setLibProperty(currentKey, selected, "Lib:sheSettings")]
    [return(0, 0)]
};{}]

[h: assert(0, "Kein Token verk&ouml;rpert oder ausgew&auml;hlt!")]
"she_hasTokenRights(selected)" returned true (by setting its macro.return=1), the "true" branch of the if gets executed, but "return(0,0)" did not return. This was quite tricky to pin down ;-), because if an other macro/UDF (e.g. she_debug("something")) is called before "return(0,0)" everything worked. I assume that's because the UDF "she_debug" did not set "macro.return" and thus apparently clearing it.

Post Reply

Return to “MapTool”