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

Get help using Construct 2

Post » Fri Apr 04, 2014 4:39 am

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
Last edited by part12studios on Wed Apr 09, 2014 2:37 am, edited 1 time in total.
B
59
S
9
G
1
Posts: 970
Reputation: 6,611

Post » Fri Apr 04, 2014 6:02 am

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.
You think you can do these things, but you can't, Nemo!
Just keep reading.
Just keep learning.
B
65
S
16
G
9
Posts: 1,429
Reputation: 12,728

Post » Fri Apr 04, 2014 3:40 pm

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
B
59
S
9
G
1
Posts: 970
Reputation: 6,611

Post » Fri Apr 04, 2014 5:55 pm

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
You do not have the required permissions to view the files attached to this post.
You think you can do these things, but you can't, Nemo!
Just keep reading.
Just keep learning.
B
65
S
16
G
9
Posts: 1,429
Reputation: 12,728

Post » Fri Apr 04, 2014 7:01 pm

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
B
59
S
9
G
1
Posts: 970
Reputation: 6,611

Post » Sun Apr 06, 2014 9:55 am

@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.
You do not have the required permissions to view the files attached to this post.
You think you can do these things, but you can't, Nemo!
Just keep reading.
Just keep learning.
B
65
S
16
G
9
Posts: 1,429
Reputation: 12,728

Post » Sun Apr 06, 2014 8:41 pm

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
B
59
S
9
G
1
Posts: 970
Reputation: 6,611

Post » Mon Apr 07, 2014 4:28 pm

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.
B
59
S
9
G
1
Posts: 970
Reputation: 6,611

Post » Mon Apr 07, 2014 4:33 pm

part12studios wrote: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
Game design is all about decomposing the core of your game so it becomes simple instructions.
B
54
S
22
G
18
Posts: 2,123
Reputation: 17,150

Post » Mon Apr 07, 2014 4:46 pm

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.
Last edited by part12studios on Mon Apr 07, 2014 5:03 pm, edited 1 time in total.
B
59
S
9
G
1
Posts: 970
Reputation: 6,611

Next

Return to How do I....?

Who is online

Users browsing this forum: corpvs2 and 23 guests