What's the easiest way to work with tons of text? [Solved]

0 favourites
From the Asset Store
_______ Huge collection of metal fixtures ________
  • Hi there,

    I'm working on an app that has Jokes. I've been looking at C2's data and storage options and I'm just not sure which would be the right way to handle it. I'm trying to keep it as simple as possible. I don't want to access an online database. what i would love is just to import a spreadsheet or text file. I just want the data baked into the C2 app.

    doing something like. random(1,100) = 54.. go grab line 54 and display the Joke(54a) and punchline(54b) in Joke Text Object and Punchline Text Object.. next joke.. random(1,100) = 63.. etc.. etc..

    I see array's and dictionary, but looking at the actions they have, I didn't get a clear sense of how i'd get the data into C2.

    What would be the most straight forward approach to this? In the past I did a project that had numerous text bodies, but made them actual text objects with unique text in each and copied that data over to the display text. this was "ok" but it was really unruly and while i got through the project, it was a pain and that was dealing with a lot less bodies of text.

    Any advise or tips would be much appreciated

    Thanks!

    Caleb

  • Use ajaxand import it via json.

    Then you can load the json into your flavor of choice. Array, dictionary, even a variable.

    You can even import a text file and there is a plugin by rex which does cvs file. Lots of options available.

    Couple tuts in tut section on importing data using ajax.

    I found putting data in json and loading it into dictionary worked well.

    dictionary needs "Key" and "String"

    Key has to be unique so

    "1" "joke 1 goes here"

    then you can use random to select a number and display that joke.

  • ok so i have the cvs plugin and i see i can load a "cvs string". I have a test.cvs file I exported from Excel.

    I'm just not clear how i "read" the data in a given text file from json. Where would the file reside so that when the app launches it grabs the data? would it go in the generic "file" folder?

    for example.. i found this cool site thanks to a coder buddy of mine.. http://www.convertcsv.com/csv-to-json.htm

    and it gives me this json data:

    [ { "Joke 1":"Joke 2", "Punchline 1":"Punchline 2" }, { "Joke 1":"Joke 3", "Punchline 1":"Punchline 3" } ]

    but then it's like.. where do i stick THIS? and how would I access it still.

    I didn't see any tutorials that talk about "import data ajax"

    Maybe XML would be possible? the code above reminds me of it a little.

    you mentioned "I found putting data in json and loading it into dictionary worked well." how do you actually do that?

    Thanks!

    Caleb

  • Tutorial

    Basically it is simple.

    In tut it is loading xml.

    Attached image is loading json into dictionary.

    Now when something happens...

    Now you can set text to dictionary.get(whatever you want to get like random(1,39) )

    Well, something along those lines.

    If I have time I will do some example, but its weekend, and I am away from pc most of it. So maybe monday. But you will probably figure it out. It isn't that complicated. Array yes, but simple dictionary or xml shouldn't be a problem.

    The manual will give you want you need. And the image is what is needed to load data into dictionary

  • I will definitely look into this and let you know if I get hung up! Thanks for the added explanation! you've been a great help!

    Sincerely,

    Caleb

  • part12studios

    Here is an example I did for you. It is bloated so that you can see what is happening. Feel free to use less objects and place data directly into desired location (removing variables) I just wanted you too see as much of the process as possible.

    Oh, It is using array not dictionary. Dictionary is easier, so thought I would do one in array so you can see. Also array allows for easier multi data usability.

    So you can have joke, punchline, category, whatever.

    Easy way to edit json file. Save as project and go to files. Open the json file in your favorite editor and see structure and edit.

    Hit button on left to generate random card data.

  • sweet thank you so much for this sample! I'll be tackling this head on tomorrow (monday) and report back how it turns out!

    Sincerely,

    Caleb

  • ok i'm digging in it now. I saw you have a "json" file in there. is this simply making a text file and changing the extension? I was able to open it with wordpad and it looks good so i imagine this is true and will move forward on that assumption but i at least wanted to mention it.

  • ok i'm digging in it now. I saw you have a "json" file in there. is this simply making a text file and changing the extension? I was able to open it with wordpad and it looks good so i imagine this is true and will move forward on that assumption but i at least wanted to mention it.

    Indeed it is, however you might want to make sure that the encoding of the text file is UTF-8

  • ok thanks! Yea otherwise my txt files would be default to ANSI.

    can anyone explain some of the values found in this json file? specificially the header stuff. c2array is fine i guess, but what does "size" mean? 13,6,1?

    {

    "c2array":true,

    "size":[13,6,1],

    "data":[[ I do see he has 13 cards (Card00 through Card12) but i don't understand what the 6 and 1 represent. below the data line you see this ["Card 00"],

    ["Content 01 - Card 00"],

    ["Content 02 - Card 00"],

    ["Content 03 - Card 00"],

    ["Content 04 - Card 00"],

    ["Content 05 - Card 00"]

    ]

    I do see 6 rows although one of them is he header.. not sure if that matters.. but if that is the case then what does the 1 represent in the three numbers "13,6,1"?

    Then i follow the idea that DeckCards1 gets completed.. move on.. I see load Json strong "AJAX.LastData" is this a commonly used command to simply put all of the data that was loaded from the CData2.json into an array?

    I've never used sprite fonts before. I was just looking to use plain text fields for displaying data, but I think I can see what's going on. trying to rebuild something using this as a guide.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I'm guessing the 13,6,1 is the array size for x,y,z.

  • ok i'm trying to break this down to better understand the syntax.. i need a joke and punchline that would go in different text objects.. so i imagine i'll need to make two json files.. is this the right syntax below?

    {

    "c2array":true,

    "size":[3,1,1],

    "data":[[ ["Joke1"],

    ["Joke2"],

    ["Joke3"]

    ]]

    }

    what is the purpose of "c2array"? is it a unique name? I don't cee "c2array" anywhere in the event sheets. If I import two json files i just want to be sure that c2array name is something that either needs to be unique or in common.

    also you mention X, Y, Z? i'm only used to that being used in terms of 3d coordinates. what would the x y and z represent in this case with c2?

    Thanks!

    Caleb

  • part12studios - I don't think you have the right syntax there. For arrays, the X, Y, and Z represent the 1D, 2D, and 3D coordinates for the array. In C2, you want to specify your array size and you always do this in X, Y, Z terms. So, even if you have a simple array of 10 items (i.e., you only need the X-coord), you still specify the size as (10,1,1).

    If you had a 2D array of 5x2, then size = (5,2,1).

    You would not need two files for your jokes and punchlines, unless you wanted to. I would just put joke, punchline, joke, punchline in a 2D array and access the jokes and punchlines with [x,y] coordinates.

    Joke 1 = [0,0]

    Joke 1 punchline = [0,1]

    Joke 2 = [1,0]

    Joke 2 punchline = [1,1]

  • Manley23 has the right xy approach above.

    And

    "c2array":true, is what construct2 uses to json the data into either array or dictionary. It isn't part of json, but a c2 thing

    What I did was build it in construct2 first. Used the array download to download to json. And used that json to be imported.

    Attached is capx of events used to create array, then download to json. I toggled the include CreateDatabase event sheet.

    I am using the xy, but out of habit I include z = 1

    There are 13 because arrays count 0 as 1, which is why I minus one from TotalCards to get correct display of number cards. Array.Width is 13, but we don't want card 0.

    So we 13-1=12 cards

    And random(1,13) because we don't want to include card0

    The above is only for cosmetic purposes. Showing Joke 6of12 for example.

    Now that you have how i created the database, play around make your own then import it into files and change the Ajax->Request to reflect your json file.

  • awesome thanks! i'll keep at it with this new info! Thanks to you both for your help with new (and kinda confusing to me) subject

    Thanks!

    Caleb

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