0 votes

im using a project to learn to code, and in my getting anywhere lol

im trying to make a .json file generator that will read from a folder that users can easily interact with.
the .jsons in this folder will be like prefabrications. so i need to copy the information from this file and immediately create a file in another directory that has some changed information based on what the user input in the project settings.

i tried putting this in a code block but it kept kicking it out. im doing something wrong here

EX: { "group": "CHANGE", "type": "CHANGE", "pattern": [ "0 2", "345", "678" ], "key": { "0": { "item": "CHANGE" }, "2": { "item": "CHANGE" }, "3": { "item": "CHANGE" }, "4": { "item": "CHANGE" }, "5": { "item": "CHANGE" }, "6": { "item": "CHANGE" }, "7": { "item": "CHANGE" }, "8": { "item": "CHANGE" } }, "result": { "item": "CHANGE", "count": 1 } }
this file has 12 different things to change and that's not uncommon. when you have over 200 items in your mod alone this gets tedious..
but this is a recipe and they arent that bad compared to the blocks in the game.

ill be setting up some sort of spreadsheet with all the blocks, items, potions, effects, etc etc from minecraft. that comes to a total of 2400 entries so ill have to get creative on caching that.

in Engine by (16 points)

that example .json looked right before i posted....

I don't have the faintest idea what your question is about. It's confusing. Can you explain your problem more specifically? Which code you used, which issue you had, and what you expected?

sorry i didnt realize, i need help figuring out how i create a new file from an existing file but things in the new file get replaced by user input

for example
"variants": {
"": {
"model": "MOD_ID:block/MOD_OBJECTblock"
the MOD
ID and the MOD_OBJECT would change depending on the users settings and user input

the MODID would be set in a file at the start of the project
the MOD
OBJECT would be set when the user is creating this .json class

i was about dead when i made that post, so im sorry for the confusion.

so basically how do i copy a .json file then replace some keywords in the new file (WITHOUT EDITING THE ORIGINAL) with user input, then create the new file.. then use one of the user input strings as the new name of the .json file you just created.

im sorry if its still confusing for people, im not good at putting words in a coherent paragraph. my mind wanders.

maybe something like this????

func _readJsonsItem():
var file = File.new()
file.open("user://prefabs/assets/MOD_ID/models/block/block.json", File.READ)
var content = file.get_as_text()
return content

func _writeJsonModelItem():
now here i change the key words in the file
then save it as a new .json file

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.