We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Im having problems saving a string to a txt file. The file.txt is in the data folder. I'm not sure what I am doing wrong.
else if (hb0.value >= hb0.max) {
frameNum++;
image(images[frameNum/10 %images.length], 800, 600);
port.write(1);
println("Here is the achievment");
image(achievment2, 700, 100);
String words = "Achievement achieved";
String[] list = split(words , " ");
saveStrings("file.txt", list);
println("They are saved");
Answers
Needs dataPath() in order to get "/data" folder path:
dataPath("file.txt")
.That worked thanks :D
GoToLoop I do have one more question when it comes to saving strings... I am trying to do the same thing with a users ID and password. Can u tell me how I can get this to work please? it says saveStrings expects parameters like "saveStrings(String,String[]") :/
Have you read its reference already?: https://processing.org/reference/saveStrings_.html
Some older threads w/ that: https://forum.Processing.org/two/discussions/tagged?Tag=savestrings()
Yes I have read all of those...So does that mean because my accounts is String[],String[] its not going to work?
If you got 2 String[], it's less of a hassle to just use 2 saveStrings() for 2 separate files.
The two Strings[] are like this tho, they are both apart of accounts, will this not work?
GoToLoop: dataPath() isn't even in the reference. What is that function doing again? I'm curious.
Line 1:
final StringDict accounts = new StringDict(...);
Line 51:
saveStrings(dataPath("file.txt"), accounts);
StringDict is not a String[] array.
saveStrings( String filePath, String[] fileToSave )
Try: https://processing.org/reference/StringDict_valueArray_.html
String[] colors = inventory.valueArray();
or something like
Im getting an EOF error with the for loop :/
It shows up again? Well, devs think we're too stupid to have such useful functions such as dataPath()!
Although they're
public
, they're rather meant for library developers, not for us sketchers! [-(dataPath() and its cousin dataFile(), gets us the full path for the subfolder "data/".
GotToLoop: Man I sure need to pay more attention to the github.
AmyM: Whoops, forgot the new String[];