modifying and saving a text file with typescript?

Recommended Posts

loading a text file in phaser with typescript is trival with a simple:"reference", "url")
however attempting to write or modify external text files appears to be way more complicated.

I'm guessing this is for security reasons, but still don't see why there can't be a "game.write.text()" method or something similar?

Share this post

Link to post
Share on other sites

Not sure what would be your use case? When you publish your game "url" will be remote http server. In theory you could write a method that will send HTTP POST or PUT request to server and then server will write (if you program it to do so) the content to file. But once your game will have more than one player it will probably lead to data corruption. Better say what you want to achieve and then maybe someone will be able to point you toward proper solution. 

Share this post

Link to post
Share on other sites

If you have your data in an array you could do it in that way:

let textarray = ["text1", "text2", "text3"];

let txtContent = "data:text/csv;charset=utf-8,";
textarray.forEach(function (rowArray)
   let row = rowArray.join(",");
   txtContent += row + "\r\n";
let encodedUri = encodeURI(txtContent);
let link = document.createElement("a");
link.setAttribute("href", encodedUri);
link.setAttribute("download", "my_data.csv");
document.body.appendChild(link); // Firefox;


Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.