问题
Here I have a code that I was playing around with. It loads a string within my file and saves an unimportant one.
var file = "1";
var result;
var meString;
var splitMeString;
function preload() {
result = loadStrings("assets/save/"+file+".txt");
}
function setup() {
createCanvas(1000,650);
}
function draw() {
meString = result+'';
splitMeString = splitTokens(meString, ',');
text(meString,20,20);
console.log(splitMeString[2]);
}
function mousePressed(){
saveStrings("happy");
}
but how would I save a string to a specific location? Say I wanted to overwrite the file ("file")?
回答1:
Questions like these are best answered by looking in the reference.
According to the reference, the saveStrings()
function can take three arguments:
Syntax
saveStrings(list,filename,[extension])
Parameters
list
String[]: string array to be writtenfilename
String: filename for outputextension
String: the filename's extension
So it sounds like you're looking for something like this:
saveStrings(yourArray, "file", "txt");
Also note that the third argument is optional, so this should also work:
saveStrings(yourArray, "file");
来源:https://stackoverflow.com/questions/50282600/how-to-save-strings-to-specific-location-in-p5-js