How to save strings to SPECIFIC location in p5.js

送分小仙女□ 提交于 2019-12-11 10:14:47

问题


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 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");


来源:https://stackoverflow.com/questions/50282600/how-to-save-strings-to-specific-location-in-p5-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!