write to text file doesnt write to the file

I gave gdevelop a command to write a string of text to a text file:

So these two can successfully write to the file and read from it. However the file is always empty :astonished:
So it does not write to the file that I am telling it to write to at all. Playing the game moves the data to god know where and there is no way for me to figure out what gdevelop is exactly writing to the file (how)

Btw I am doing this to see what syntax gdevelop uses to structure the data in the text file. There seems to be no documentation on that at the wiki.

You need to load the file in memory, then write in it, and finally commit your changes by closing/unload it.

And btw, write/read from file might not work if you use it for dialog purpose in a web project.

For example : my dialogs are written in a text file, but all accuentated characters are messed up when I read them and show them in my html5 game. In that case, my dialogs must be written directly into the events.

I didnt know. Thanks, I will try it.

Do they get messed up only when you host the game on a server?
Are you using non latin characters for the dialogue?
This might be an encoding issue. Perhaps maybe submit a bug report about it.

I am sorry, but it still doesnt actually write to a file on my file system. Can somebody please share an example file, where gdevelop writes to and reads from a text file on the file system (not memory) -for a html5 game!

Thanks in advance.

In HTML5 games, GD saves-in and reads-from the browser cache, I think. Maybe you could debug your file system in native platform, when everything is OK return to the HTML5 platform :slight_smile:

it wont let me switch to native :frowning: i started the project as html5

Can you share a an example text file with multiple groups and items in it?

“file” in the sentence of the action is misleading but that’s because these actions were originally meant for the native platform :

-With native platform, real (XML) files are written.
-With HTML5 platform, there is no way to write on the file system. Still, to be able to save data like hi score, I used WebStorage (en.wikipedia.org/wiki/Web_storage) to simulate files.

So your “files” are written properly, but not as real files but as JSON stored inside the browser. That’s a limitation of HTML5 (but make sense when you think about it, it’s just harder to understand because when you’re testing your game you make no distinction between your machine and the fake server created by GD and used to serve the game).

No way, in the extensions window, right click over Native platform ==> Use this platform, then you can preview your game with the native and browser modes (use the little arrow below the Preview button), let us know if this doesn’t work :slight_smile:

I tried that, still no luck :frowning: Gdevelop just doesnt show the option to play it as a native when I enable native as a platform. This is possibly another bug.

Can you guys just share with me an example project where gdevelop html5 game gets a number of different text strings from an external text file. I just want to see how a text file is structured (root/group/item–>contents) in order to use it for a story type game experiment.

The wiki page doesnt seem to have any data on the subject/

You have to close the scene and re-open it for the change from HTML 5 → Native platform to take effect.

Ok I got it to write to text file to see its structure.

<?xml version="1.0" encoding="ISO-8859-1" ?> <root> <dialogue1> <test1 texte="this is a dialogue 1" /> <test2 texte="this is a dialogue 2" /> </dialogue1> <dialogue2> <test2 texte="this is a dialogue 2" /> </dialogue2> </root> <root2> <dialogue2> <test2 texte="this is a dialogue 2" /> </dialogue2> </root2>

I noticed that it says “texte”. Shouldnt it be “text” ? :smiley: I suppose because the author is french

If possible I would have it not have the word “texte” at all. just " <test2=“this is dialogue 2”/> "

Good to know that you get it working :smiley:

GD needs to know if the value saved is a number or a string, you know, to convert it correctly :slight_smile:

About “texte” instead “text”, is it really a problem? I mean, the idea is to write and read from GD, at least I don’t write the text structure myself, it’s painful and unnecessary (and you can bug your data). If the values saved to the file are fixed (because it seems that you want to write them yourself)… why don’t use strucures? :confused:
By the way, it seems that you just need to change “texte” by “text”(or whatever you want) in the lines 263, 330 and 333 from this file: FileTools.cpp

Anyway I think that having some french words in the program is a nice detail, they are there since the origin of the software, words as “texte”, “oui”, “afficher”, etc. are over all the code (where people that just use the software don’t notice), I don’t know if 4ian is planning to change it someday, but I think it’s nice and weird, just beautiful :sunglasses:

The idea is to use an external text file to store the game’s story dialogue (npc speech). This way it is easy to edit it, easy to change it, easy to translate it.

I think that there should be something in the wiki about this - especially if the file itself needs to use specific french words in its syntax - you gotta include it in the software’s documentation how such file is structured. A tutorial of sorts would be nice. A lot of people like to have story driven games. Those games rely heavily on a lot of text to communicate to the user. In order to write a good, reliable NPC/dialogue system you need to have the engine access data that is stored in a convenient way that doesnt rely on the engine to be edited.

If xml files are not the best way to go about this with gdevelop, then what is? How would you implement that?

Can you load a json file from your hard disk instead? Are those more manageable and easier to write/read?

Thanks in the advance for the advice. :slight_smile:

Also how about this:
If the text has quotes (=“this is a string”) - the engine thinks its a string. If it doesnt (=66) - then its a value.
The less repetative writing you gotta do in an xml file, the better.

Anyways, best type of file I found so far to store this kind of stuff seems to be CSV tables. I already made a feature suggestion for gdevelop to load and interpret CSV tables:
viewtopic.php?f=22&t=6235
Why csv tables? They require the least amount of typing for telling the engine when to use what avatar , sound effect and show text. Instead of typing over and over again “avatar=john” for each line john says - you just simply have a column called avatar and you type John in the cells that correspond to the ID of the dialogue line that is running.
It is the most convenient way so far. Less typing than jason for this sort of job.
The csv file is a simple text file - it can contain the data of multiple tables - so it is sort of like a 3d array in a text file with the ability to get to cells by calling them via their row/column names- that opens the opportunity for some very cool scripting that arrays can not do. It is awesome! :mrgreen:

Gdevelop can not do it though. Cant interpret csv files.
c2rexplugins.weebly.com/rex_csv.html

That’s what I was talking about earlier: as long as you use english characters, all is fine. But use é or è or ï or any accentued characters, and the html5 export f*ck it up. It’s an issue within GD, where the project file is in UTF-8 and the generated js files are in Unicode (or something like that), while your txt files are in whatever encoding you use.
I don’t think you can resolve it at your level.

The best way to do this is to hardcode your dialogs into an external event.
Then, use a variable to get the right text.
Ex:
If showDialog > 0 then
if showDialog == 1 then put “bleh bleh bleh” in text variable myCurrentDialog
if showDialog == 2 then put “bloo bloo bloo” in text variable myCurrentDialog
etc.
showDialog = 0 //exit the external event
end if

That way, you can use myCurrentDialog in any way you want.

Then, for translation purpose, you can encapsulate the firt “if then end if” into another if.
Ex :
if myCurrentLanguage == 0 then end if//english text
if myCurrentLanguage == 1 then end if //french translation of the english text
etc.

Notice this will generate lots of copy/paste.
Meaning you better be sure of your dialog system before translating it.
Or you will have lots of corrections to make for every tinkering.

Ok, now this would be useful if I could load up an spreadsheet file exported as an XML file from another application.

There is however a problem in the way gdevelop reads these values!

To get to a value , it is using this:

<test1 texte="this is a dialogue 1" />

However values in most XML files, in open office and gnumeric exported tables look like this:

<table:table table:name="Sheet1" table:style-name="ta1"> <table:table-column table:style-name="co1" table:number-columns-repeated="2" table:default-cell-style-name="Default"/> <table:table-row table:style-name="ro1"> <table:table-cell office:value-type="string" calcext:value-type="string"> <text:p>This is dialogue1</text:p>
with <text:p>This is dialogue1</text:p> being the final value I want gdevelop to read!

How do I tell gdevelop to read a group name as a value?

With gnumeric I get this:

<Cells> <Cell Row="0" Col="1" ValueType="60">words</Cell> <Cell Row="0" Col="2" ValueType="60">avatars</Cell> <Cell Row="1" Col="1" ValueType="60">Hi I am george</Cell> <Cell Row="1" Col="2" ValueType="60">george</Cell> <Cell Row="2" Col="1" ValueType="60">and I am wanda</Cell> <Cell Row="2" Col="2" ValueType="60">wanda</Cell> <Cell Row="3" Col="1" ValueType="60">tets </Cell>

How do I get the dialogue text stored to values?