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

asked Mar 12, 2019 at 20:54

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');
});
answered Mar 12, 2019 at 21:09
Sign up to request clarification or add additional context in comments.

Comments

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.