U8g2 arduino screen

i'm using u8g2 to contol an arduino screen, why i can't use a variable(y_pos) to change the position of the line i write ?

 if (i==ItemCurrent)u8g2.drawStr(2, y_pos, ">");   

int y_pos=22;
u8g2.firstPage();
do {
u8g2.setFont(u8g2_font_5x8_tr);
u8g2.drawStr(32,8,screenMenu[PageNumber].page_title); //(x,y,..)
u8g2.drawStr(2,63,"BACK");
u8g2.drawStr(30,63,"SELECT");
u8g2.drawStr(80,63,"DOWN");
u8g2.drawStr(115,63,"UP");
for(int i=ItemMini ;i<=ItemMax ; i++)
{
if (i==ItemCurrent)u8g2.drawStr(2, y_pos, ">");

  if(screenMenu!= NULL){

   u8g2.drawStr(9, y_pos, screenMenu[   screenMenu[PageNumber] .item[i].next_page    ]. page_title);  // code que corrigé et qui doit bien marcher    
   y_pos =  y_pos+12 ;
  }
}

} while ( u8g2.nextPage() );

Please copy-paste a minimal example. i.e. something that we can build and run.

The Forum tutorials show you how to post code properly.

The drawStr() method should work fine with variables.
However you need to be careful how you write for() loops inside a firstPage(), nextPage() procedure.

David.

You need to reset y-pos in the do{ } while (u8g2.nextPage()); loop.
Each iteration needs to draw exactly the same at the same place.

The firstpage/nextpage loop is writing to the display in pages. The display is divided up into subsections by the controller, each subsection being a "page". Each time through the firstpage/nextpage loop, the library processes all the display commands, filling a page buffer with ONLY the display data that goes onto that particular page of the display, and ignoring anything outside of that page. To properly display all the pages, each iteration of the firstpage/nextpage loop needs to produce identical output, otherwise you end up with inconsistencies between pages (such as a variable that displays across two pages having a different value on the two pages).