1

this code below will successfully write "apple" into the text file called save.txt

//Write Text File
var total = $gameActors.actor(1).name();
var path = window.location.pathname.replace(/(\/www|)\/[^\/]*$/, '/');
if (path.match(/^\/([A-Z]\:)/)) {
      path = path.slice(1);
}
path = decodeURIComponent(path) + "save.txt";
var fs = require('fs');
fs.appendFile('save.txt',"apple", function(err) {
    if (err) throw err;
    console.log('created]');
});

I want to write the variable "total" into the file

I have tried

fs.appendFile('save.txt',total,
fs.appendFile('save.txt',var total,
fs.appendFile('save.txt',(total),

but none works. Any help is appreciated Thanks in advance

1 Answer 1

1

Try this:

var fs = require('fs');

var total = $gameActors.actor(1).name();
if( !total ){ total = 0; }

fs.appendFile('save.txt', total, function(err) {
    if (err) throw err;
    console.log('created');
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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.