We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Yesterday I had success using saveStrings() but when I copy the code into my current script, it saves gibberish in the file.
console.log() shows the output string is forming correctly but the saved file contains only "∫w^~)fi" (without quotes).
Here's the code causing trouble (note gridSquare is an array)...
function createData() {
dataList = startX + "," + startY + ",";
dataList = dataList + gridSquare;
list = split(dataList, ',');
}
function writeData() {
var fileName = "data" + fileNum + ".txt"
saveStrings(list, fileName);
console.log(list);
}
Since the list string looks good and the file is generated, I'm at a loss as to why the data hasn't saved as it does with the standalone script.
EDIT: It seems to work from Firefox but not from the P5 editor.
Answers
https://forum.Processing.org/two/discussion/18471/french-carachters-trough-xml
I don't think that answers it. I'm using the standard P5 index.html template (with a few added .js entries) so I assume it is not a UTF issue. Plus it works from the standalone script, and it works in Firefox. I tried Chrome but only got as far as "Loading..." I'll have to check that out tomorrow (it is image intensive).
Maybe a restart will fix it :) 1am here now, so off to bed. Thanks.
UPDATE:
I saved a copy of the file and started testing by commenting out lumps of code until a simple file saved correctly.
saveStrings("some text", "data.txt");
It worked until I reinstated the loadStrings() call in preload().
dataArray = loadStrings('data2.txt');
Then I got gibberish again in the output (in a 6-byte file). Interestingly, it doesn't prompt to save when it fails, but does prompt when it works.
And...it works if I take the loadStrings line out of preload() and put it in setup() - and yet the in/out files have nothing to do with each other.
It works fine in Firefox, so it looks like there's some issue with the P5 editor but I'm a bit new to make that call. I can't test in Chrome because I get the "Cross Origin" error loading a local image file, so I gave up.
I've already explained to you that "some text" isn't an Array, but a String: L-)
https://forum.Processing.org/two/discussion/18554/savestrings-makes-file-one-character-per-line-p5-js#Item_4
And that saveStrings() demands its 1st argument to be an Array:
http://p5js.org/reference/#/p5/saveStrings
Fixed call:
saveStrings([ 'some text' ], 'data.txt');
O:-)Use "--allow-file-access-from-files" at your Chrome-based browser's shortcut:
http://chrome-allow-file-access-from-file.com/
I'll consider myself suitably chastised - but that's not the cause of the problem :)
The following code does not work for me in the P5 editor (OS X 10.10.5, P5 0.6.1) unless I comment out the loadStrings line. Note that the load and save are not related to each other...
I've never used that IDE. And generally it's not up-to-date most of the time.
I prefer an online IDE for it though: :D
When running offline, pay attention to the ".html" file.
It determines which charset is allowed for all JS programs. 8-X
Very confusing... In preload() you load 'data2.txt'. But you save as 'data1.txt' in setup(). @-)
Yes, they are different things. They weren't always different things but I changed them for this simple test to see if there was some conflict with trying to save over the loaded file. It made no difference what they were called. For some reason, loadStrings messes with saveStrings - but only in the P5 editor. It works fine in Firefox.
I noticed I used single and double quotes- but this isn't the issue either (I'm not sure if either is preferred though).
Like I've warned about, avoid the p5.js editor for now. :-&
In JS we can use double quotes
""
, single quotes''
and even back-ticks``
for string literals! :>With regards to the Google Chrome issue, I found a Mac solution but it still won't open the program - although it no longer shows any errors at all.