<br>Hello Godotboys ( and maybe Godotgirls ?).<br>I have several panels who are detected by an area attached to the player character. These panels provide strings to the player node and they are displayed in a label.<br>The project is for learning purpose and for the moment I use mainly assets from the official demos.<br><br><img title="Image: http://i4.photobucket.com/albums/y123/Brice2nice/YourPanel_zpsngnyszqk.png" src="http://i4.photobucket.com/albums/y123/Brice2nice/YourPanel_zpsngnyszqk.png" alt=""><br><br>The exported var of the panels instances, (who could be a NPC also) is not very convenient to store text.<br>I can type a single line only.<br><br><img title="Image: http://i4.photobucket.com/albums/y123/Brice2nice/panelProperty_zps86d4zbcx.png" src="http://i4.photobucket.com/albums/y123/Brice2nice/panelProperty_zps86d4zbcx.png" alt=""><br><br>I would rather this kind of property (don't know how to get this on my node).<br><br><img src="http://i4.photobucket.com/albums/y123/Brice2nice/TextPropertyExample_zpsfywtg3eh.png" alt=""><br><br>&nbsp;But in both case the text can be lost easily. For example if I modify the panel original scene.<br><br>How do you resolve these noob problems ? Thanks in advance and sorry for my bad english.<br><br><br>

I'm not entirely sure what you mean by "But in both case the text can be lost easily". If you have the text in a variable node how can it be lost easily?

Try Having: onready var text = "text here" And then in _ready() set the labels text property to the text. Should prevent "losing" the labels text. I'm on mobile that and tad busy so cant help with multiline textfield (if thats what you want).

Thanks for your answers.<br>Maybe I should say " signs" instead of "panel". It's like the signs in SuperMario 64 for instance.<br><br>The sign scene have an "export var" so I can edit the text for each instance of this scene.<br><br>The property, into the inspector dock, is a bit limited to type texts who are longer than one sentence. And I can't delete these nodes without delete the texts. OK you will ask me " Why the hell you want to delete these instances ?"<br><br>Don't worry about that. I'm not a game developer and I just ask about the " professional" way to store text and to access it, and how to proceed with Godot.<br><br>

Quick reply: Save your texts as json files, there's good info somewhere in the docs. You will be very close then to have a localization on your game, that too can be found in the docs.

I made some tests to fill a dictionnary with a json file. Like this.<br>

var PanelText = {}<br><br>func _ready():<br> PanelText.parse_json("res://Ress/AdventureRess/panelText")<br>

<p><br></p><p>It throw an error in the debugger : " Error parsing JSON: Expected ' { ' at line 0 "</p><p>Here is the file</p>

{<br> "Panel_1": "Hello"<br>}<br>

&nbsp;I don't understand what I'm doing wrong. Maybe because I'm a complete noob with this stuff.<br><br><br>

I'm sorry to be annoying. I'm lost into the File api.<br><br>

func save(content): var file = File.new() file.open("user://save_game.dat", file.WRITE) file.store_string(content) file.close() func load(): var file = File.new() file.open("user://save_game.dat", file.READ) var content = file.get_as_text() file.close() return content

<br>parse_json() need the string from the json as argument ?<br>store_string() wait for a string but it's the thing I want to pull from the json. <br>get_as_text() is for files who contain something inside. How I should start please ?<br>

<br><br>

@NeoD said: I'm sorry to be annoying. I'm lost into the File api. func save(content): var file = File.new() file.open("user://save_game.dat", file.WRITE) file.store_string(content) file.close()

func load(): var file = File.new() file.open("user://save_game.dat", file.READ) var content = file.get_as_text() file.close() return content

parse_json() need the string from the json as argument ? store_string() wait for a string but it's the thing I want to pull from the json. get_as_text() is for files who contain something inside. How I should start please ?

I replied to myself on Q&A.

https://godotengine.org/qa/8291/how-to-parse-a-json-file-i-wrote-myself

I clicked on answered by mistake. It still unresolved.


extends Node

var dict = {}


func _ready():
 var file = File.new()
 file.open("res://Ress/panelTextn2.json", file.READ)
 var text = file.get_as_text()
 dict.parse_json(text)
 file.close()
 get_node("Area/Panel/Label").set_text(dict["text_1"])

This code works only with the editor. When exported the app doesn't found the json. As you can see the script doesn't create the json file because I want to edit text directly into the file during the game developement.


Try going back to file.open("user://file_path") You must be close to getting it right. Good luck!

Godot doesn't export .json files by default, you need to add a filter for that on "Export" -> "Resources" tab.

If you want to keep the text in the scene itself, you can export the variable as a multiline string:

export(String, MULTILINE) var text

Then you can edit this variable in the editor much like for a label node.

6 years later