Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

textutils.serializeJSON keys are in qoutes #39

Closed
Lion4ever opened this issue Dec 11, 2015 · 13 comments
Closed

textutils.serializeJSON keys are in qoutes #39

Lion4ever opened this issue Dec 11, 2015 · 13 comments

Comments

@Lion4ever
Copy link

Reproduce:
-Summon a cow
-run commands.entitydata("@e[r=10]",{Motion={0.0001,1.8,1.8}})
Expected result:
-cow flying into the distance
Real result:
NBT of cow: {"Motion":[0.00001,1.8,1.8],Motion:[0,0,0]}

@Lion4ever
Copy link
Author

Side Note: I used 0.0001 because it need to be a double and would not work with an integer

@dan200
Copy link
Owner

dan200 commented Dec 13, 2015

ok, so here's the issue:

The JSON specification (http://www.json.org/) defines that object keys must be quoted strings. So textutils.serializeJSON() is correct here. Many Minecraft commands (ie. /tellraw), obey this specification, and expect and accept objects in this format.

However, some older commands (such as /setblock), expect their data in a bastardised, incorrect JSON format. I could provide an option for serializeJSON to emit strings in this format, but when autoconverting tables, commands.blah() wouldn't know which one to use.

Unsure what to do here.

@dan200
Copy link
Owner

dan200 commented Dec 13, 2015

More info on the differences here:
http://minecraft.gamepedia.com/Commands#Raw_JSON_text (JSON)
http://minecraft.gamepedia.com/Commands#Data_tags (Not JSON)

@Lion4ever
Copy link
Author

what are the options?
-hardcode the qotation option based on the commands method called
-no quotations and the user has to provide ""strings like this""
-add an option to the serializeJSON Method
-file a minecraft bug report like this one, for the old methods: https://bugs.mojang.com/browse/MC-83460

@dan200
Copy link
Owner

dan200 commented Dec 13, 2015

Ok, decided on a solution:

The signature of serialiseJSON is now:
textutils.serializeJSON( value, bNBTStyle )
If the second parameter is true, quotes are stripped from object keys, it defaults to false.

When the autogenerated commands.blah() methods encounter tables, they serialise by passing in true, except for the methods "tellraw" and "title", as the wiki incates that those are the only two methods which use proper, non-bastardised JSON.

These changes will be in 1.76pr4.

@dan200 dan200 closed this as completed Dec 13, 2015
@Lion4ever
Copy link
Author

that is a great solution 👍

@BombBloke
Copy link
Contributor

Could the affected functions in the commands table - eg commands.setblock - be rigged to set this flag to true if they find themselves calling textutils.serializeJSON? They don't seem to do so under pr6, meaning the coder has to pre-convert their tables to strings before passing them to the affected "command" functions.

@dan200
Copy link
Owner

dan200 commented Dec 18, 2015

Unless theres's a bug in my code, that's exactly what happens in pr6. Can
you give me an example of a command that doesn't work and what the expected
result is (i'm not to hot on commands)?

On 18 December 2015 at 11:34, Bomb Bloke notifications@github.com wrote:

Could the affected functions in the commands table - eg commands.setblock

  • be rigged to set this flag to true if they find themselves calling
    textutils.serializeJSON? They don't seem to do so under pr6, meaning the
    coder has to pre-convert their tables to strings before passing them to the
    affected "command" functions.


Reply to this email directly or view it on GitHub
#39 (comment)
.

@dan200
Copy link
Owner

dan200 commented Dec 18, 2015

(by command here i mean "line of lua code that calls commands.blah()")

On 18 December 2015 at 11:38, Daniel Ratcliffe dratcliffe@gmail.com wrote:

Unless theres's a bug in my code, that's exactly what happens in pr6. Can
you give me an example of a command that doesn't work and what the expected
result is (i'm not to hot on commands)?

On 18 December 2015 at 11:34, Bomb Bloke notifications@github.com wrote:

Could the affected functions in the commands table - eg commands.setblock

  • be rigged to set this flag to true if they find themselves calling
    textutils.serializeJSON? They don't seem to do so under pr6, meaning the
    coder has to pre-convert their tables to strings before passing them to the
    affected "command" functions.


Reply to this email directly or view it on GitHub
#39 (comment)
.

@BombBloke
Copy link
Contributor

Apologies, I can no longer reproduce. Either the issue is intermittent, or more likely, there was something else wrong with my table; having restarted the game since I can no longer check my command history, so we'll go with "I'm crazy".

@dan200
Copy link
Owner

dan200 commented Dec 18, 2015

Could you provide a test case anyway? I'd like to confirm/double check for
myself

On 18 December 2015 at 12:04, Bomb Bloke notifications@github.com wrote:

Apologies, I can no longer reproduce. Either the issue is intermittent, or
more likely, there was something else wrong with my table; having restarted
the game since I can no longer check my command history, so we'll go with
"I'm crazy".


Reply to this email directly or view it on GitHub
#39 (comment)
.

@BombBloke
Copy link
Contributor

Sure:

commands.setblock("~ ~1 ~ minecraft:standing_sign 0 replace", {["Text2"] = "\1671Hello", ["Text3"] = "\1674World"})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants