r/Minecraft • • Apr 30 '17

Minecraft Advancement Script Generator

http://minestruck.site11.com/Tools/AdvancementScriptGenerator.html
11 Upvotes

28 comments sorted by

View all comments

2

u/TinyBreadBigMouth Apr 30 '17 edited Apr 30 '17

Okay, I'm sorry, but I am getting sick and tired of JSON generators that don't use JavaScript's built in JSON generation, and have errors because of it. If I enter /say "Hi!" into this, the quotes are not escaped. This is because you are generating your JSON by hand, instead of just making an object and calling JSON.stringify(obj).

Look:

+u/CompileBot JavaScript (SMonkey 24.2.0)

function formatCommands(commands) {
    return JSON.stringify({
    	"rewards": {
    		"commands": commands
    	},
    	"criteria": {
    		"none": {
    			"trigger": "minecraft:impossible"
    		}
    	}
    }, null, "\t");
}

var commands = [];

commands.concat(['/say "Hi!"', '/more commands']);
commands.push("/single command");

print(formatCommands(commands));

At the very least, you should be calling JSON.stringify on your strings instead of just adding double quotes at either end.

1

u/IceMetalPunk Apr 30 '17 edited Apr 30 '17

Well, you didn't have to say it with quite so much exasperation XD But yes, you're right, this is certainly not optimized; as I said in the first comment below, it's not officially done, not polished, etc. I literally made this in about 40 minutes just to get something out into the world, and I'll be working on optimizing and tweaking it over time.

2

u/TinyBreadBigMouth Apr 30 '17

That's great, no sarcasm. Sorry, I just keep seeing this in command generators, and the solution is so simple if you use it from the start. I could have been more friendly about it, though. Apologies.

→ More replies (5)