michael-buschbeck / mychs-macro-magic

A simple, sane, and friendly little scripting language for your Roll20 macros.
MIT License
1 stars 1 forks source link

`settracker()` shows strange behavior on non-token entries #228

Closed phylll closed 3 months ago

phylll commented 4 months ago

This script...

!mmm script
!mmm
!mmm   for charName in m3mgdPlayerCharacters where not isdenied(charName.character_name)
!mmm     set trackerData = trackerData, { token: charName.token_id, value: charName.Gw + charName.ItemBGewandheit + charName.modGw + charName.gRusGW }
!mmm   end for
!mmm   set trackerData = { title: "Runde", value: "1", formula: "+1" }, trackerData order (...left.value > ...right.value)
!mmm   do settracker(trackerData)
!mmm   do showtracker(true)
!mmm
!mmm end script

... calls settracker() with this argument ...

(
  {formula: "+1", title: "Runde", value: "1"},
  {title: "Wulfric MacConuilh", token: "-NwLfyzGpRIFzaiBfLjq", value: 98},
  {title: "Finn MacRathgar", token: "-NwLfwokDd8fTTCjI4Yu", value: 88},
  {title: "Ufix Steinbrot", token: "-NwLfyPlcAF4e5XqfrHJ", value: 82},
  {title: "Yorric MacRathgar", token: "-NwLfzVfSaKz9zbG9Iu3", value: 64},
  {title: "Titos Panathos", token: "-NwLfxYqKzsRwzAtLb4i", value: 57}
) ◀️ trackerData

... and results in setting the tracker with all the correct character names, but the "Runde" entry misses the title and gets a seemingly random token from the board assigned (which does not have to be part of the list). Otherwise, the entry works (the formula is being applied when clicking through the players and moving to the next round).

I get the same behavior when using gettokens() to pull the tokens on the board (unsurprisingly, since the problem is with the token-less "Runde" entry). Adding token: "" does not change anything.

michael-buschbeck commented 3 months ago

Via experimentation: The non-token formula-bearing entry works if you do pass an intentionally invalid token for it, like so (...using two entries here so you can meaningfully click through the rounds):

!mmm do settracker({formula: "+1", title: "Runde", value: 0, token: "blah"}, {formula: "+2", title: "Doppelrunde", value: 0, token: "blubb"})

No, it doesn't make sense. I'll guess they changed how the API behaves. I'll dig deeper.

michael-buschbeck commented 3 months ago

It seems that token: "" or similar (including token: absent) now resolves some (random?) nameless token on the page, so the settracker() code now branches into the "this entry represents that token" bit.

I'll explicitly special-case token: undefined or absent to avoid that.