garrysmod icon indicating copy to clipboard operation
garrysmod copied to clipboard

Use Brackets for keys in PrintTable

Open JustPlayerDE opened this issue 5 years ago • 6 comments

To avoid confusion when there is [357] and ["357 "] for example.

JustPlayerDE avatar Dec 13 '20 00:12 JustPlayerDE

You are assuming that keys are always either numbers or strings, the concatenation will throw an error with other key types.

CornerPin avatar Dec 13 '20 01:12 CornerPin

You are assuming that keys are always either numbers or strings, the concatenation will throw an error with other key types.

you are right i totally missed that, i will try fix/comply with that as soon as i get to my computer again (thanks for the info tho)

JustPlayerDE avatar Dec 13 '20 02:12 JustPlayerDE

image

Maybe this is a bit cleaner? if ( isstring( key ) && key != key:Trim() ) then key = "[\"" .. key .. "\"]" end

robotboy655 avatar Dec 17 '20 18:12 robotboy655

image

Maybe this is a bit cleaner? if ( isstring( key ) && key != key:Trim() ) then key = "[\"" .. key .. "\"]" end

I agree that this will fully fix the issue while adding less stuff to the console

but i may not be able to answer the question if it is cleaner as i also prefer consistency a bit (in that case the key could also be Entity(1)["[\"Fuck \"]"] as there is no reference tho)

JustPlayerDE avatar Dec 18 '20 00:12 JustPlayerDE

A fair point. I am not sure what to do about it, either way it's gonna be either confusing or just increase amount of irrelevant symbols on each line.

robotboy655 avatar Feb 01 '21 18:02 robotboy655

Also there is the same kind of issue with table to string, it doesn't correctly print keys

ExtReMLapin avatar Feb 26 '21 09:02 ExtReMLapin