1

I made a game with javascript using this tutorial as a base: http://html5gamedev.samlancashire.com/making-a-simple-html5-canvas-game-part-3-drawing-images/ How do I get it to write the data from the item counter (var itemCounter = 50;) to a text file named savedata.txt? I googled it, but no helpful results came up. Can someone help me?

asked Dec 2, 2013 at 2:31
3
  • 3
    If you want to store the file on the client, then the answer is: you can't. Commented Dec 2, 2013 at 2:33
  • Check this topic: link Commented Dec 2, 2013 at 2:33
  • 1
    As @FelixKling says, if the file is on the client you can't... We will need more info about what exactly are you trying to do, but you can try with Local Storage Commented Dec 2, 2013 at 2:41

4 Answers 4

1

Technically, you can create a server with nodejs [which is built with javascript]. Details can be found here

answered Dec 2, 2013 at 2:36
Sign up to request clarification or add additional context in comments.

Comments

1

Its not possible to store the data as a file on the client. But you can use localstorage, websql, indexeddb or simply cookies for it. Note that all of these storages have different properties in terms of lifetime.

You could also create a blob using the blobapi and then create a dataurl and request the user to save it, using drag and drop + fileapi to read the data, this approach however will make it easy for users to modify the data.

answered Dec 2, 2013 at 2:38

Comments

1

Writing a file is posible with the new FileWriter and FileSystem APIs.

More mature solutions (not using files) have already been mentioned

answered Dec 2, 2013 at 3:11

Comments

0

Javascript does not support working with files, for data storage several options are available:

answered Dec 2, 2013 at 2:39

2 Comments

I already have a file called savedata.txt. I want it to write to it, not create it.
Updated the Answer, javascript is sandboxed preventing it from reading, writing or creating files. Although some newer APIs add this support ( see my other answer)

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.