Creating a diary app - or using Structs and Arrays and Storage

Hello, I am just getting started with Gdevelop and enjoring making lots of animated games, but I also need to do something more data-oriented.

My hope is to make a web app that lets people keep a track of their blood pressure, stores it in local storage (i.e on the device)… but when needed to be shared can be either downloaded as .csv or emailed… or using whatever means to get it to a doctor. I’ve got all the form items working (even multiple choice/drop downs which are sadly missing).

My plan was to use 3 global variables to handle this.

entryStruct // a diary entry including name, bpOne, bpTwo, height, weight, datestamp etc.
diaryArray // a list of entrStructs
diaryJSON //where I will serialise diaryArray for saving into storage (persistent in web right?)… and at some point later, read it in and write out as .csv.

Firstly, does this all add up and look reasonable? (Even though it may be an unusual use case for gdevelop)

Secondly, why isn’t there no-code, menu-based ways to create a Struct? It seems I maybe can call these items with code, but there always seems to be levels of coercion going on…

In my mind, when I click the “ADD ENTRY” button, my pseudo-code might look something like this…

//BUTTON CLICKED on Main Screen Adding a diary entry

    // create a struct to store the diary entry
    //How do I create a notional Struct? Remove a child is the only option available? = GlobalVariableString(name)//we asked for it on the previous screen
    entryStruct.bpOne = bpOneInput.Value()
    entryStruct.bpTwo = bpTwoInput.Value()
    entryStruct.height = heightInput.Value()
    entryStruct.weight = heightInput.Value()
    entryStruct.datetime = "10:20 06/02/2023" //automatically filled in to be now.

    //add it to an array
    diaryArray .addChild( key=datetime, data=entryStruct )

    //save it to Storage
    storage.diary = GlobalVarToJSON( diaryArray )
    //close structured data "storage" //to do a hard save?

This approach (if I’m going down the right track) would be made easier if the Global Variables were in the list of objects I could create and assign values to.

Thanks for any guidance.


p.s Just another note, it seems some of the content on the forum is very old and maybe isn’t up-to-date any more.

Is this forum entry still relevant?

It suggests I can just instantiate an Array item child by merely using it in context (am I right?)…like this…

Do = Variable(myStruct[VariableString(count_1)][VariableString(count_2)].childVar) To Variable myVar

But I don’t know how to get to do a “Do”?

Maybe a simpler way of asking this question is: Is there an example of a CRUD app that uses an Array of Structs - like a blog app or something?

I feel like this is “nearly there”



I feel I’m getting there, things are saving AND showing up in the debugger, but I don’t think I’m doing the right thing, which is saving a struct as JSON into array… then using GlobalVariableToJSON() to save an Array of JSON strings (which are structs).

This is what I’ve got so far (getting closer) but not quite there. Ideally I’d like to dump and load an Array of Structs to a JSON object in storage (assuming this is possible?).

Almost getting there.

I can save my data as an Array of JSON strings (of Structs) but I don’t feel this is the best way of going. And I can’t get it to store and load this array properly.

Surely the best way to work, like I said earlier, is to have an Array of Structs that gets JSON’d, and stored in storage as “diary”… then re-vivify it when loading… I think at the moment, I’d have to re-vivify each JSON string.

My project is here if anyone might cast an eye over it and spot what I’m doing wrong.


No, it’s not completely relevant anymore.

But it was the most efficient available way to do it in that version of GDevelop.

Just going from your screen shot, have diary array set out like:


And then save it like:


There’s no need to jsonify the collection so often.

Thanks for your suggestion…

I save a diary entry (and write it to json) every time because I would expect a user to want to see previous entries listed (not got to that bit yet)… and add a new entry then quit the app/game.

I have to jsonify the diaryArray because storage items have to be a String, they can’t be a list of objects like this [ {bpOne:120, bpTwo:90}, {bpOne:145, bpTwo:100}].

Is there a better way of saving a persistent (complex) object. Or maybe an Extension that helps me do it more easily?

Thanks again.

That’s what the last line of my screen snip does - it jasonifys the array of structures into a string and sends it to storage.

1 Like

Ah yes! Got you! Sorry… big thanks. Will try to implement that now…