I need Help with save a int

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?

Hello,

I was not seeing the text in your example until I used:
fullScreen();

:)

Yes! :slight_smile: …

I added thank you xD*

1 Like

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

@akenaton that’s just too much for me i haven’t been programming with processing for long

Resources < Click here to expand !

I encourage you to review the resources available here:

:)

@Rogo === that is easy to do; try by yourself, put your code and i can help if needed

Okay thank you :slight_smile:

how can I make the int a string?

Type str() in reference.

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();
}

You can’t use same name for int AND string.
Use for instance :
String score_str;
int score_int;

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

Did you declare the variable “int score_int;” as global on the top of your sketch?

1 Like

:slight_smile: :slight_smile:

@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();
}
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);