Importing text data

Discussion and feedback on Construct 2

Post » Sun Apr 01, 2012 9:46 am

Hi guys,

I have just started writing a word puzzle game. The issue that I am facing is that there is no way to import data easily. I have searched the forum but I cannot find anything.

I need to create an array that will hold a lot of words. How can I do this without having to painstakingly enter the data manually?

Maybe this could be added to the list of suggested features if there is a demand for it of course.

Cheers

Simon

EDIT: I know I can use AJAX for the game when hosted on a website but I am interested in developing for Android phones, so I want to include the data in a APK.simwhi2012-04-01 09:51:02
B
26
S
5
G
5
Posts: 151
Reputation: 6,279

Post » Sun Apr 01, 2012 11:04 am

Perpaps with the FileReader - plugin and a local text-file. Haven't tried it but with the right policies for the app this should work.
[Edit]Have forgotten the Load JSON-Plugin Joe72012-04-01 11:09:13
B
14
S
6
G
5
Posts: 173
Reputation: 4,742

Post » Mon Apr 02, 2012 1:34 am

Hi Joe7,

Thanks for the ideas. I don't really want to use a plugin to read a file at run-time. I'd like to insert the data directly into an array. Ideally, I want to store the data in a spreadsheet and create a script that can insert the data into the source code of a C2 game.

My games rely heavily on data as they are more educational. Inputting data directly in C2 is cumbersome and prone to potential errors (abeit user created). It would be nice to find an easy way to manage this.

simwhi2012-04-02 01:39:24
B
26
S
5
G
5
Posts: 151
Reputation: 6,279

Post » Mon Apr 02, 2012 1:42 am

I think there is a plugin for exactly what you want. Look through them all.
B
90
S
30
G
24
Posts: 3,189
Reputation: 32,400

Post » Mon Apr 02, 2012 1:51 am

Hi Squidster,

Thanks for the suggestion. However, as mentioned in my previous post, what I'm really looking for a workaround to directly insert data into a non minified version of the source code.


   
B
26
S
5
G
5
Posts: 151
Reputation: 6,279

Post » Mon Apr 02, 2012 9:17 am

@simwhi:
here's a short example(capx) with arrays in the source-code of the index.html. To call the functions from within C2 I've used the Call Javascript-Plugin. Afaik calling javascript-functions isn't possible without a custom plugin.

If you really want to insert data directly in the non minified version of the file c2runtime.js - I would recommand write an own plugin. When exporting a project, C2 inserts 'some' sourcecode of all the in the project used plugins in this file.

Just to mention: I personally would never implement it both possibilites shown above, because
1) a non minified version brings you no advantages - only the possibility to write messy javascript-code.
2) a plugin written only for one project isn't very useful for the next projects.
3) If I would need something like the example above I would write the scripts in an external file - eg "myScriptfile.js"
4) I've created some quizzes too and I personally prefer loading JSON-datas(per javascript) or anyway with ajax - just to seperate the datas completely from the runtime. That way I win the possibility to reuse the quizzes. The plugin load JSON is a small sideprodukt of a quizz I've made.. Joe72012-04-02 10:46:02
B
14
S
6
G
5
Posts: 173
Reputation: 4,742

Post » Mon Apr 02, 2012 5:24 pm

Is there any existing plugin that would read a XML file?
B
19
S
5
G
5
Posts: 48
Reputation: 4,843

Post » Mon Apr 02, 2012 5:45 pm

@ simwhi. I believe its possible. Have a look at my tutorial - http://www.scirra.com/tutorials/276/who-said-you-cant-create-a-database-with-construct2.
If I have gotten you right you need to have many global variable, array and webstore and if you wont mind please send me your capx so that I can have a deeper look what your saying and try to find a solution.
B
13
S
4
G
3
Posts: 53
Reputation: 3,356

Post » Mon Apr 02, 2012 11:55 pm

You can read a file in with ajax and do whatever you want with it in the success callback.

I don't know what limitations the c2 ajax plugin places on this but with regular jquery it's a nonissue as long as the file you're loading is in the same domain.
B
10
S
5
G
1
Posts: 37
Reputation: 1,631

Post » Tue Apr 03, 2012 2:35 am

Thanks guys for all your suggestions. What a great community!

I'm developing my apps for the Android marketplace, so I want to package the data (words in this case) into a single APK file. I'm not sure how to do this other than manually type each word into an array within C2. I don't want to do this as it will be very time consuming. I want to find a way to inject the data into the source code of my game.

A feature to import a CSV text file directly into C2 arrays would be awesome!

@Zaks I will have a look at your tutorial in a day or so. Many thanks.
B
26
S
5
G
5
Posts: 151
Reputation: 6,279

Next

Return to Construct 2 General

Who is online

Users browsing this forum: eli0s, Lof, RageByte, Yahoo [Bot] and 7 guests