How to store large text

Get help using Construct 2

Post » Sat Dec 17, 2011 11:47 am

Hey!

I want to build a game, somewhat RPG-like.

I need it to display rather large text, different text in more than one place. Ideally I would store this text separately in some XML or txt file.

For example, I have a button "Intro", when the user clicks, they see a messagebox of sorts with some 3-4 paragrahps of text (some 200-250 words). They click OK, message box gone.

Then they click Play, and are taken to a new layout, and another message box pops with another message, adding some more info to the story. In the new layout they click Help and see another message.

All these messages I would like to have in one place where I can easily edit them.

Can this be done in Construct 2?

Thanks in advance.
B
14
S
5
G
7
Posts: 235
Reputation: 5,175

Post » Sat Dec 17, 2011 11:55 am

Try out my Extra Expressions plugin, which has Base64 encode/decode capabilities.

Just create your text in some text editor (without formatting, obviously), select all & copy into base64encode.org, encode and paste the resulting string into a variable or something.

Then when you want to recall the text, simply use the decode expression where you normally enter the text.

That way you can store large amounts of text in, say, an array (e.g. for each chapter) and pull it on demand.Mipey2011-12-17 11:56:39
B
62
S
21
G
12
Posts: 1,910
Reputation: 13,155

Post » Sat Dec 17, 2011 9:36 pm

Thanks Mipey! That sounds like it should work, but I was hoping for some more automatic solution, i.e. less manual steps when changing the story text.

Any other ideas?
B
14
S
5
G
7
Posts: 235
Reputation: 5,175

Post » Sun Dec 18, 2011 10:22 am

Well, right now Construct 2 is pretty limited when it comes to implementing new features via plugins. It's still at a pretty early stage, I guess.

It would be ideal to store the text separately, yes, however currently there doesn't seem to be any way to load these text files. At least all my attempts have failed. Javascript can't load files directly, it depends on external sources, such as querying server script and getting data with AJAX. And that doesn't work in localhost mode.
B
62
S
21
G
12
Posts: 1,910
Reputation: 13,155

Post » Wed May 02, 2012 9:13 am

Did something really simple because I wanted the ability to easily edit large chunks of text:
Created an Instance Variable for each block of Text to be used attached to just one Text Box.
Each Instance Variable was named according to it's intended destination and/or scene - I used numbers and a 3 character scene code.
Then used events to place text into just 3 text boxes that are reused throughout the game.
I also used 7 different themes for directing how the text is displayed for a given scene
There are over 400 text events and it works real quick with no major garbage.
Couldn't use AJAX as the client required app to run offline.
Didn't use an array as I didn't see the point of having to map out the event logic twice
Hope this gives folk some ideas!
B
16
S
4
G
1
Posts: 18
Reputation: 2,568

Post » Wed May 02, 2012 9:56 am

You might try storing the text as JSON. You could use this plugin to move it in and out of C2:
http://www.scirra.com/forum/plugin-load-json_topic50331.html

I think there's also some native support for JSON in arrays as of R87.

To make the data easy to deal with, you could create a database and have it spit out text chunks in JSON format. If you use something like Ruby on Rails...
http://www.rubyonrails.org

...you could create a basic CRUD app to handle the data pretty quickly. When you're ready you could output the data into .json files which you could store in a folder alongside the C2 code. Or, if you can store the database online, you might be able to access it with AJAX requests. I don't know much about C2's AJAx capabilities, though.

There's some initial overhead with this method, but it would make data entry and keeping track of the structure much easier.

Edit: There's also XML support in R87, and Ruby On Rails will spit out XML as well. XML has lots more overhead than JSON, though.joeykid62012-05-02 10:08:22
B
12
S
5
G
5
Posts: 26
Reputation: 4,001


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 28 guests