coolwhip Posted December 10, 2017 Share Posted December 10, 2017 loading a text file in phaser with typescript is trival with a simple: this.game.load.text("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? Link to comment Share on other sites More sharing options...
Odk Posted December 10, 2017 Share Posted December 10, 2017 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. Link to comment Share on other sites More sharing options...
Fenopiù Posted December 11, 2017 Share Posted December 11, 2017 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 link.click(); Link to comment Share on other sites More sharing options...
Refeuh Posted December 12, 2017 Share Posted December 12, 2017 Does it have to be an external file ? Standard behaviour would be to rely on the local storage for persistence of application-specific data. Link to comment Share on other sites More sharing options...
Fenopiù Posted December 12, 2017 Share Posted December 12, 2017 Yes, you can edit the code to upload instead of download the file ;-) Link to comment Share on other sites More sharing options...
HMR's Posted July 13, 2018 Share Posted July 13, 2018 I'm new to Nodejs, Can you tell me how can i give the path to download the file to a specific location? Link to comment Share on other sites More sharing options...
Recommended Posts