Append to my .txt file and save

0 favourites
  • 10 posts
From the Asset Store
Source File, music and art pack for Android Negotiator
  • Here's our goal:

    via AJAX we retrieve a .txt. file, append an additional string/record to the .txt file and then save the updated .txt file.

    We know how to retrieve and search the .txt file using AJAX. We're having the problem in appending the .txt file and resaving it.

    Thanks in advance!

    Tagged:

  • You can only do this in NWJS export (for desktop).

    In HTLM5 export (for web) you can invoke download of the changed txt file, but you can't save it automatically without showing "Save as" dialog to user.

  • Dop,

    I found a previous post (https://www.construct.net/en/forum/construct-3/how-do-i-8/save-everything-butunique-146447?kws=save%2bjson%2bto%2bserver) to saving a file. I incorporated the code, but instead of the file saving to the server (where the HTML export of the game is located) it is downloading to my local computer.

    What am I doing wrong?

    Jefferson

  • Are you using "Invoke download" action?

  • I was using "Invoke download of string".

  • Actually this has gotten a bit more complicated. Instead of a string I'm using a dictionary (it's easier to modify during the game itself). I also found this tutorial using the AJAX POST process, again my results were not positive. I really don't care which process I use - I'm ranting a bit here - just need to get a file "saved" to my server and not the player's local machine.

  • "Invoke download" does exactly what it says - invokes download.

    There is no easy way to upload a file to web server. You need to send data to a PHP script, which will create a file. Check out comments in this post:

    construct.net/en/forum/construct-2/how-do-i-18/savecsv-file-server-137535

  • I think I'm gonna owe you a couple of cups of coffee, eh?

    I'm almost there...

    I was able to save the dictionary file to the external server via php (See code below)

    Now I'm having a problem retrieving the file and loading it into a dictionary. IS it because the php language above is only for saving and not retrieving? Or am I using the improper load-in language in the event sheet - see below

    AJAX>Request URL>"http://www.myserver URL address/text.txt"

    On completed>Dictionary>Load from JSON string AJAX.LastData

    Is this making sense?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I haven't tried that PHP script. Are you sure it's working and the file is saved on your server? Can you see its contents if you simply open its URL in a browser?

    In this case you should be able to request it with AJAX.

  • Figured it out. Just had to play with it and study up on php. Just my personal impatience with my learning curve.

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