flag shenannegins

TIL you can set the flags key on a document to whatever you want to (e.g. a string). This is a sure fire way to completely ruin someone else's day, or your own day when another module un-does this by setting a flag 'correctly'.
game.actors.getName('A Character').update({
['flags']: 'A value'
})

game.actors.getName('A Character').data.flags // 'A value'

game.actors.getName('A Character').setFlag('world', 'someKey', 'some string value')

game.actors.getName('A Character').data.flags // { world: { someKey: 'some string value' }}
game.actors.getName('A Character').update({
['flags']: 'A value'
})

game.actors.getName('A Character').data.flags // 'A value'

game.actors.getName('A Character').setFlag('world', 'someKey', 'some string value')

game.actors.getName('A Character').data.flags // { world: { someKey: 'some string value' }}
21 Replies
Calego
Calegoā€¢3y ago
dnd5e for instance gets big mad when its flags disappear from an actor.
Unknown User
Unknown Userā€¢3y ago
Message Not Public
Sign In & Join Server To View
Calego
Calegoā€¢3y ago
It seems that core doesn't care
Calego
Calegoā€¢3y ago
No description
Calego
Calegoā€¢3y ago
this falls squarely under "play stupid games win stupid prizes" lol
Calego
Calegoā€¢3y ago
No description
Calego
Calegoā€¢3y ago
speaking of... I want to try this with items or like data itself, but am too scared
Calego
Calegoā€¢3y ago
omg lol
No description
Calego
Calegoā€¢3y ago
Alright well. TIL update has great power and thus comes with great responsibility.
Unknown User
Unknown Userā€¢3y ago
Message Not Public
Sign In & Join Server To View
Calego
Calegoā€¢3y ago
[removed gif] oo no that looks like it actually hurt no more of that gif thanks
Calego
Calegoā€¢3y ago
much better
Unknown User
Unknown Userā€¢3y ago
Message Not Public
Sign In & Join Server To View
Calego
Calegoā€¢3y ago
lol
LukeAbby
LukeAbbyā€¢3y ago
I feel like this is a prime example of Javascript loose casting LOL and the unfortunate effects
Daniel Thorp
Daniel Thorpā€¢3y ago
Is this a "bug"?
Calego
Calegoā€¢3y ago
I would not categorize it as such. If I got sent a bug with this at work, my reply to it would be "... don't" and I'd WONTFIX it.
Daniel Thorp
Daniel Thorpā€¢3y ago
Makes sense, thanks
Calego
Calegoā€¢3y ago
if I couldn't get away with telling them to "just don't" I'd say something like:
The amount of complexity and performance overhead that would be introduced by adding validations to this low-level API do not outweight being able to prevent the edge case described by this issue.
šŸ˜›
LukeAbby
LukeAbbyā€¢3y ago
in all fairness setFlag isn't that low level. but yes the edge case is small and the validation is probably a WONTFIX it's a pretty expected result of Javascript casting imo