Import and Export a text file

Get help using Construct 2

Post » Fri Mar 22, 2013 6:12 am

I've been searching and trying to figure out how to do this properly for over an hour now to no avail, hopefully there are some smart cookies on here who can help.

All I'm wanting is for my project to import and export a simple text file. For example the file may look like this

Monster
2
Coin
23
Cat
3

And when I click a button, it will import those numbers into the C2 file and I can then add or subtract and then send the numbers back to the same file they came from.

Any help is appreciated, and if possible, I'd like to not have to use a plug-in
Using R238 for all examples
B
60
S
17
G
6
Posts: 363
Reputation: 9,125

Post » Fri Mar 22, 2013 5:38 pm

Is your text file online? If yes, then use the AJAX OBJECT to read (get) the file and to write (post) in it.
I made 2 games so far: www.ID-Games.net
B
9
S
2
Posts: 47
Reputation: 1,315

Post » Fri Mar 22, 2013 5:42 pm

Interactions with the filesystem are very limited browser-side. I don't think there is any way to write directly into a file with no download dialog and what not...   
B
46
S
17
G
18
Posts: 847
Reputation: 13,802

Post » Sat Mar 23, 2013 1:04 am

Ideally the file would not be online, but could put it online if it has to be.
Using R238 for all examples
B
60
S
17
G
6
Posts: 363
Reputation: 9,125

Post » Sat Mar 23, 2013 1:08 am

If the file could be online - AJAX and a small PHP script on your server should menage your save/load needs. This could be the difficult part, because you have to check many possible incoming and outgoing information cases.

If you would like to keep it locally, maybe the cookie plugin is exactly what you need:

http://www.scirra.com/forum/plugin-Cookies_topic51805.html

I don't think there is another C2 easy workaround way to use a local file from within your browser.XManBG2013-03-23 01:16:14
B
11
S
3
G
3
Posts: 79
Reputation: 3,343

Post » Sat Mar 23, 2013 1:26 am

Project files for everything that is loading from a file, but I don't think you can modify its content from your game.

You may also want to check out webstorage and the score example I give in this tutorial which pretty much allows you to put a default set of datas on your clients computer and "play" with it.
I'd recommend it over a third part plugin as it is built-in.Kyatric2013-03-23 01:27:19
New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 6,999
Reputation: 57,793


Return to How do I....?

Who is online

Users browsing this forum: djcrazypants, marekmk and 6 guests