We are about to switch to a new forum software. Until then we have removed the registration on this forum.
This is the code, this code saves the written text into a txt, but it always saves it into the same one, so the older text written in the txt file gets deleted. I would like it to save it into a new txt everytime the program saves it . How do i do so.
and another thing: how do i load the text in txt into the document, by clicking on another button :)
thanks in advance :)
String str = "";
void setup(){
size(400,400);
}
void draw(){
background(0);
fill(255);
text(str,20,20,100,height-20);
fill(128);
if( over() ){
fill(196);
}
rect(width-20,height-20,20,20);
}
boolean over(){
return( mouseX>width-20 && mouseY > height-20 );
}
void keyPressed(){
if( keyCode == DELETE || keyCode == BACKSPACE ){
if( str.length() > 0 ){
str = str.substring(0, str.length()-1);
}
} else {
if( key != CODED ){
str += key;
}
}
}
void mousePressed(){
if( over() ){
saveIt();
}
}
void saveIt(){
String[] strs = { str };
saveStrings( "text.txt", strs );
}
Answers
New file name: you could make a nee file name based on the date today and the time including seconds - see reference, it’s all there
For a file open dialogue see
https://processing.org/reference/selectInput_.html
Is it possible for you to make an example for me
A file dialog to choose a file can be found by checking previous posts as well: https://forum.processing.org/two/search?Search=selectinput
Also check the controlP5 or G4P library to use buttons in your sketch. You can install either library using the library manager in the Processing IDE. Then, go to files>>examples>>Contributed libraries and either ControlP5 or G4P to see the examples.
Kf
The only thing that i would like to is use the loadStrings(), buti don't really know how to load the txt file as text.
the other thing is to make sure when i save the file it saves it into a txt, and when i save another time it saves it into another txt not the same as before that but new
i told you how to do this
you need a file dialog to select a text file. after that you can use loadStrings
@Caseguy
Check the reference and run the code provided there. Become familiar with the main components of a Processing sketch and run the examples. When you find a code that could potentially work for you, and you have a specific question, provide your code and all the details.
You can also check previous posts and find something that fits your needs. Try searching loadStrings for example.
Kf
I have tried the SelectInput(), but i cant seem to make it work :(
Show your code and we look into it
It's above
No, that's MY code. We want YOUR code. Show us what changes you have tried to make to it.
This really didn't need to be a new Question, you could've just continued the old one.
Also, you've posted someone else's code without credit, which is a bit of a crappy thing to do, not to mention confusing.
Sry I will never post more, I forgot to mention TfGuy44. Bye :)
See, the idea of the forum is that you ask for help with your code. Like post code and ask something like „in line 30 I need to check the mouse against my nice Load Button but I don’t know how“.
The forum is not here to ask others for complete programs.
These are just some rules here to get used to.
Now you wrote you tried selectInput and I asked to see your attempt and you said it’s above but above there is no selectInput.
So when you want to learn how to program, try to write a code with selectInput and then show attempts and ask and learn.
The trick with selectInput for example is that draw() doesn’t wait for it. Instead you need to check whether its result has arrived and then move on. Use a Boolean variable for example which tells you if the result has arrived (see example of selectInput to understand).
Best regards, Chrisir
Of course instead of saving with a date / time file name there is also a normal selectOutput dialog, so the user can type a file name and select a folder. See reference selectOutput
Are you using Windows?
I'm using windows
And this is TFGuys code: I tried to use it as you said but can't figure it out.
still room for improvement, e.g. what happens when "Window was closed or the user hit cancel."
FFS, just have a counter.
I'm guessing this is homework. Who needs to write a text editor in this day and age?
Thanks for trying to help Chrisir. I made my own program, didn't use TfGuy44 code, I got live help, wich very much usefull.
And TfGuy44 thanks for trying to help me, but why do you have to be rude? I'm just a student that need help with some simple programming from the forum.
And koogs It's for our exam, it's a part of our report(Yes you can call it homework).
Actually It's a very smart way you made your "|" line. Really like (If possible can i use it in mine ?)
Sure!
Should i post the code I made, and yours here so if people finds this disscisuon they can get the help/code ? It's only 73 lines
Please do.
The blink thing is not by me, by the way. It’s a variation of a Code by gotolooop iirc
new version