Rogo
May 16, 2020, 9:25am
1
Hello I wanted to ask how I can Save the int below in the Text because someone has an idea?
int score = 0;
void setup(){
orientation(PORTRAIT);
}
void draw(){
background(0);
fill(#FFFFFF);
textSize(75);
text(score, displayWidth/2, displayHeight/12);
}
void mousePressed(){
++score;
fill(0);
rect(0, 0, displayWidth, displayHeight);
}
Hello
Do you want to save the score on hard drive and load it next time?
glv
May 16, 2020, 10:08am
3
Hello,
I was not seeing the text in your example until I used:
fullScreen();
:)
Rogo
May 16, 2020, 10:10am
6
and how can I if. the number from 99 to 100 which automatically pushes to the left?
@Rogo === supposing that you want to save the last score:
you create a .text file that you put in your data folder; at this point you write in your text file 0 as the first score;
when launching the app you get this file and read it with loadStrings();
when exiting the app you save the new score to the same file (replacing the first one only if the last is > than the first. This can be done using the onPause();
Rogo
May 16, 2020, 10:14am
8
@akenaton that’s just too much for me i haven’t been programming with processing for long
@Rogo === that is easy to do; try by yourself, put your code and i can help if needed
Rogo
May 16, 2020, 10:38am
12
how can I make the int a string?
Rogo
May 16, 2020, 12:45pm
14
My code dont working why?
int score = 0;
void setup(){
orientation(PORTRAIT);
fullScreen();
score = str(score);
}
void draw(){
background(0);
fill(#FFFFFF);
textSize(75);
text(score, displayWidth/2.4, displayHeight/12);
}
void mousePressed(){
++score;
redraw();
}
noel
May 16, 2020, 12:55pm
15
You can’t use same name for int AND string.
Use for instance :
String score_str;
int score_int;
Rogo
May 16, 2020, 1:26pm
16
Error: 1. ERROR in /data/user/0/com.calsignlabs.apde/app_build/src/processing/test/spiel/spiel.java (at line 25)
score_int = str(score_str);
noel
May 16, 2020, 1:29pm
17
Did you declare the variable “int score_int;” as global on the top of your sketch?
1 Like
@Rogo ===
String score_str;
int score_int;
void setup(){
orientation(PORTRAIT);
fullScreen();
//size(800,1000);
}
void draw(){
background(0);
fill(#FFFFFF);
textSize(75);
score_str = str(score_int);
text(score_str, displayWidth/2.4, displayHeight/12);
}
void mousePressed(){
++score_int;
redraw();
}
Rogo
May 16, 2020, 1:42pm
20
String score_str;
int score_int;
void setup(){
orientation(PORTRAIT);
fullScreen();
score_str = str(score_int);
}
void draw(){
loadStrings("score.txt");
background(0);
fill(#FFFFFF);
textSize(75);
text(score_int, displayWidth/2.4, displayHeight/12);
}
void mousePressed(){
++score_int;
saveStrings("score.txt", score_str);
redraw();
}
Error: 1. ERROR in /data/user/0/com.calsignlabs.apde/app_build/src/processing/test/spiel/spiel.java (at line 38)
saveStrings(“score.txt”, score_str);