How to save strings to SPECIFIC location in p5.js

2019-07-26 16:20发布

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条回答
一纸荒年 Trace。
2楼-- · 2019-07-26 16:45

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 written
  • filename String: filename for output
  • extension 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");
查看更多
登录 后发表回答