How do I Save and read data [Solved]

0 favourites
  • 10 posts
From the Asset Store
Data+ is the best Data Management solution for Construct 3. It contains 4 Addons (Plugin & Behavior).
  • Hi all

    Sorry to post a question that has been asked before , it is just that all of the posts I have read I have struggled to understand and when trying the various methods struggled to see the results.

    So my current project that I keep adding to is mainly one that I use for myself, This is an app more than a game as it is more of an educational app but you could treat it as an educational game app in some places. The part that I find long winded at the moment is adding new data to it each time. This app is used to help me learn French which I use in line with the "homework" I get from my tutor.

    This is currently done by editing a text file outside of the project, adding into the project and then having to re-compile the project each time. So the data consists of verbs both regular and irregular which are help in separate text files and hold the French and English data . Then I have other text files that hold other data for this app.

    My aim would be able to add the data to the app by creating a form entry for each section that allows me to enter e.g. new verbs both their French and English counterparts and this is for the Android platform and I would like to be able to store the data locally on the device or within the app whichever is possible. This means that I can use the app offline without having to keep connecting to a remote server.

    I have looked at the various options e.g. XML , dictionary and arrays plus localstorage and some external plugins as well but I am not seeing an obvious way to do this.

    Can someone please guide me on how to do this please. I did read through some of the tutorials but some are based on remote servers and one goes through using a web storage which I believe no longer exists.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Ok i understand your problem i struggled too the first time.

    1_ Create a dictionnary for storing your verb

    key: Manger Value: Eat

    2_ For saving the dictionnary use localstorage so

    any condition -> set item "magicname" to 'dictionaryasjson' (it's an expression)

    Now save is complete

    For loading

    1-on start of layout -> local storage check if item 'magicname' exist and get item "magicname"

    2- localstorage on item "magicname" get -> dictionnary load -> LocalStorage.ItemValue

    Not sure if it's the best method but it worked for me !

    Sorry for my english im French

    Have a nice Day !

  • Ok i understand your problem i struggled too the first time.

    1_ Create a dictionnary for storing your verb

    key: Manger Value: Eat

    2_ For saving the dictionnary use localstorage so

    any condition -> set item "magicname" to 'dictionaryasjson' (it's an expression)

    Now save is complete

    For loading

    1-on start of layout -> local storage check if item 'magicname' exist and get item "magicname"

    2- localstorage on item "magicname" get -> dictionnary load -> LocalStorage.ItemValue

    Not sure if it's the best method but it worked for me !

    Sorry for my english im French

    Have a nice Day !

    Casimir

    Thank you for your reply . Your English is much better than my French !!. Some questions on this and I hope that you understand where I am coming from with these .

    1) how do I store both English and French in one record ? so for instance how would I store Je suis and I am within the same record? If I cannot do this how would I go about "linking" these ?

    2) I am also building a phrase building section which currently holds a list of phrases in English and then the various versions in French . The screen currently has a series of list boxes and the idea is to select the correct section of the phrase from each of these to make up the phrase asked. So I would need to be able to hold the sections of the phrases as well as the English version and the various French versions.

    Currently all of this data in held in various text files that are part of the project and so these would eventually need to be converted over somehow.

  • 1) it's all about the dictionnary

    let's admit that we have two textbox

    <one> you write the english word I am

    <two> you write the french word Je suis

    Create a button that do:

    On clicked do: dictionnary -> add key -> key name = texboxone.text and value = textboxtwo.text

    With this you get

    I am = Je suis

    I need = J'ai besoin

    Or whatever you want.

    2) It's where is became easely it's a simple matcher

    If every list.selectedText = good value in dictionnary so "WIN"

    Because of the language barrier if you dont understand what i say or you thinks i dont understand what you say, you can retry to ask in another way.

  • 1) it's all about the dictionnary

    let's admit that we have two textbox

    <one> you write the english word I am

    <two> you write the french word Je suis

    Create a button that do:

    On clicked do: dictionnary -> add key -> key name = texboxone.text and value = textboxtwo.text

    With this you get

    I am = Je suis

    I need = J'ai besoin

    Or whatever you want.

    2) It's where is became easely it's a simple matcher

    If every list.selectedText = good value in dictionnary so "WIN"

    Because of the language barrier if you dont understand what i say or you thinks i dont understand what you say, you can retry to ask in another way.

    Thanks for this again, on the matter of loading the saved data back to the screen, how is this done, so it is saved using local storage , how then do I load this back when the app is started?

    Sorry for the last question was not reading your first post fully due to be very tired . Thanks again for your help hopefully this will do the trick. My only issue is to now get all of the data from my text files into this format.

  • Hi again

    Trying to get my head around how to put the check in to see if the save data is there and if so to load it. I do not see the part where I can place the whole condition check if "magicname" exists then load it , as one hole condition.

  • Scrap my last post, I think I have figured this out, what I am struggling with , is how to move between the records with next an previous buttons

  • Hi

    I am not sure if I am going about the whole process correctly so I have attached my capx file here

    https://drive.google.com/file/d/0B5zCtsJ4bwwOQVRyQWNmZ0dIY1E/view?usp=sharing

    So I am trying to load the data, if it exists, when saving it then should exist , however I am struggling to load the data into two text files and move between the records. Also how does the data get stored once the application is closed ?

  • Hi again

    So the main question is, can the built in data objects handle what I am trying to do, as I do not want to try and work this out if they cannot. Sadly I also bought a plugin SQL lite database but this does not work with phonegap so that ended up as a waste of time (and a small amount of money ).

    Please can someone help me with this as it will really help me move forward with this project

  • Hi again

    I have now figured out what I was doing wrong when reading in the data and writing to it from and to the dictionary and local storage. I have then read the data into a listbox object and used that to hold and allow me to move between records. However if I want to edit an existing record on clicking on an entry from the listbox I can read that into two edit boxes. However once I have changed the data, I worked out how to update the existing entry in the listbox but my problem is then to update the dictionary and localstorage afterwards.

    I noticed that the listbox has a json option and I tried that with the dictionary but this just clears the dictionary meaning to me that the data from the listbox is not held in json format as well.

    Any help on reading this data back would be appreciated

    ** EDIT **

    Worked this out now , ended up clearing the dictionary and re-adding the values updated from the listbox each time the entry was amended.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)