[1.1.74] GUI Tags stringified keys in nested table

Post your bugs and problems so we can fix them.
Post Reply
User avatar
Posts: 31
Joined: Sat Mar 05, 2022 11:30 am

[1.1.74] GUI Tags stringified keys in nested table

Post by _CodeGreen »

Consider the following GUI element tags:
a = {"one"}
b = {"one", "two"},
c = {nil, "two"},
d = {nil, "two", "three"}

a and b are both sequences, but c and d are not.
the game will leave the sequences alone, but it will stringify the keys of the non-sequences.

Here's a command that adds a button to the player's screen with these tags, and prints out the tags the element has.

Code: Select all

/c local button = game.player.gui.screen.add{type = "button", tags = {a = {"one"}, b = {"one", "two"}, c = {nil, "two"}, d = {nil, "two", "three"}}} game.print(serpent.line(button.tags))
This is the output for the above command:
{a = {"one"}, b = {"one", "two"}, c = {["2"] = "two"}, d = {["2"] = "two", ["3"] = "three"}}
Notice how the keys for c and d are strings instead of numbers.

I'm not sure if this is intended behavior, but it's not documented on latest and left me really confused for about an hour. :P
My Mods
If you can't make it perfect, make it adjustable

Filter Inserter
Filter Inserter
Posts: 962
Joined: Thu Oct 03, 2019 7:10 am

Re: [1.1.74] GUI Tags stringified keys in nested table

Post by Honktown »

As side information, when discussed on the Discord, it based on PropertyTrees being [compatible with/existing as] json. json has the two types of containers: arrays and objects. Arrays only have numbered indices (from 1-N, a Lua sequence) and objects only have strings keys. Anything not a sequence can only be stored in JSON in an object, which causes the surprise when numeric keys are stringified.
I have mods! I guess!

Post Reply

Return to “Bug Reports”