# Help understanding a simple inventory menu

All right my friends I need some learningâ€¦

Ive been staring at the menu code for days now trying to acquaint myself with the code above. But Iâ€™m not really any closer to understanding how to get the items to go in the slots. The example can be found hereâ€¦

http://legacy.gamebuino.com/forum/viewtopic.php?f=8&t=3492

Naed says in his lil tutorial that he places the key in the slot this way with 8 and 8 being the placement coordinates.

``````if(menu_1 == 3 && key_1 == 3){
gb.display.drawBitmap(8,8,key);
}``````

But the code looks like thisâ€¦

``````if((menu_1 == 3 && key_1 == 3 && Active_slot==1) || (menu_1 == 5 && key_1 == 3 && Active_slot==1)){gb.display.drawBitmap(key_loc,keyy,key);}
if((menu_1 == 3 && key_1 == 3 && Active_slot==2) || (menu_1 == 5 && key_1 == 3 && Active_slot==2)){gb.display.drawBitmap(key_loc,keyy,key);}
if((menu_1 == 3 && key_1 == 3 && Active_slot==3) || (menu_1 == 5 && key_1 == 3 && Active_slot==3)){gb.display.drawBitmap(key_loc,keyy,key);}
if((menu_1 == 3 && key_1 == 3 && Active_slot==4) || (menu_1 == 5 && key_1 == 3 && Active_slot==4)){gb.display.drawBitmap(key_loc,keyy,key);}
``````

would this be the part of what tells the items go to one slot?

``````     if(S1==0 && S2==0 && S3==0 && S4==0){Active_slot = 1;}
else if(S1==1 && S2==0 && S3==0 && S4==0){Active_slot = 2;}
else if(S1==1 && S2==1 && S3==0 && S4==0){Active_slot = 3;}
else if(S1==1 && S2==1 && S3==1 && S4==0){Active_slot = 4;}
else if(S1==1 && S2==1 && S3==1 && S4==1){Active_slot = 0;}
else if(S1==1 && S2==0 && S3==1 && S4==0){Active_slot = 2;}
else if(S1==1 && S2==0 && S3==1 && S4==1){Active_slot = 2;}
else if(S1==1 && S2==0 && S3==0 && S4==1){Active_slot = 2;}
else if(S1==1 && S2==1 && S3==0 && S4==1){Active_slot = 3;}
else if(S1==0 && S2==1 && S3==0 && S4==0){Active_slot = 1;}
else if(S1==0 && S2==1 && S3==1 && S4==0){Active_slot = 1;}
else if(S1==0 && S2==1 && S3==1 && S4==1){Active_slot = 1;}
else if(S1==0 && S2==1 && S3==0 && S4==1){Active_slot = 1;}
else if(S1==0 && S2==0 && S3==1 && S4==0){Active_slot = 1;}
else if(S1==0 && S2==0 && S3==1 && S4==1){Active_slot = 1;}
else if(S1==0 && S2==0 && S3==0 && S4==1){Active_slot = 1;}
``````

The only other things I see are these two bits tha could give coordinatesâ€¦

``````else      if((gb.display.solid[i].spritecol == chest) && room == 1 && Active_slot == 1 && gb.buttons.pressed(BTN_A) && key_1 == 1) {gb.popup(F(" ""You got key"" "),20); key_1 = 3, S1=1, key_loc=8, keyslot=1; return true;}
else      if((gb.display.solid[i].spritecol == chest) && room == 1 && Active_slot == 2 && gb.buttons.pressed(BTN_A) && key_1 == 1) {gb.popup(F(" ""You got key"" "),20); key_1 = 3, S2=1, key_loc=26, keyslot=2 ; return true;}
else      if((gb.display.solid[i].spritecol == chest) && room == 1 && Active_slot == 3 && gb.buttons.pressed(BTN_A) && key_1 == 1) {gb.popup(F(" ""You got key"" "),20); key_1 = 3, S3=1, key_loc=44, keyslot=3; return true;}
else      if((gb.display.solid[i].spritecol == chest) && room == 1 && Active_slot == 4 && gb.buttons.pressed(BTN_A) && key_1 == 1) {gb.popup(F(" ""You got key"" "),20); key_1 = 3, S4=1, key_loc=62, keyslot=4; return true;}
``````

and

``````if (scroll1 == 1 && menuy < 0){
menuy = menuy + 2;    ////2 = menu speed down
keyy = keyy + 2;}     ////2 = menu speed down
if (scroll1 == 2 && menuy > -84){
menuy = menuy - 2;  ////2 = menu speed up
keyy = keyy - 2;}   ////2 = menu speed up
if (menuy == -84 && scroll1 == 2){
if (menu_1 > 7){
scroll1 = 0;}``````

Very specifical code. Itâ€™s can be use only if you have same gaphics and menu organization as i understand it. You will go quicker writting your own code to manage your menu, i thnik.

Lol if i knew how to do that i wouldnt be trying to ask about the given example.

OK so i wrote my own thing. Kind ofâ€¦

first i drew a big bitmap for my menu then divided it into 4 parts. the top part is just a bubble 114x32p then i made the second bitmap to connect it to the top bitmap and act as a stop for the cursor going past the slot bitmap which came next then a bottom bitmap to act as a stop for the cursor moving down.

next came the actual code. here are all the location coordinates for each slot once the bitmaps are drawn onscreen.

``````int slot1_x = 0;
int slot1_y = 48;

int slot2_x = 0;
int slot2_y = 64;

int slot3_x = 0;
int slot3_y = 80;

int slot4_x = 0;
int slot4_y = 96;

int slot5_x = 0;
int slot5_y = 112;

int slot6_x = 0;
int slot6_y = 128;

int slot7_x = 0;
int slot7_y = 144;

int slot8_x = 0;
int slot8_y = 160;

int slot9_x = 0;
int slot9_y = 176;

int slot10_x = 0;
int slot10_y = 192;

int slot11_x = 0;
int slot11_y = 208``````

now we do the the integers for each part of the codeâ€¦

``````int itemslot;

int item_loc;

int Active_slot;
int S1 = 0;
int S2 = 0;
int S3 = 0;
int S4 = 0;
int S5 = 0;
int S6 = 0;
int S7 = 0;
int S8 = 0;
int S9 = 0;
int S10 = 0;

int menu_1 = 1;
int item_1 = 1;
int item_2 = 1;
int item_3 = 1;
int item_4 = 1;``````

next we call the menu to screen by pressing the a buttonâ€¦

``````    if (ButtonA.fallingEdge()){menu_1;}

};``````

next the actual slot system which i understand and wouldnâ€™t know a better way. It goes if menu equals 3 and item 1 equals 3 and active and yada yada print a bitmap of the item in active slot 1 and gives the coordinates for he item in the bubble on screen.

``````if((menu_1 == 3 && item_1 == 3 && Active_slot==1) || (menu_1 == 5 && item_1 == 3 && Active_slot==1)){tft.writeRectNBPP(slot1_x,slot1_y,16,114,4,item_1);}
if((menu_1 == 3 && item_1 == 3 && Active_slot==2) || (menu_1 == 5 && item_1 == 3 && Active_slot==2)){tft.writeRectNBPP(slot1_x,slot1_y,16,114,4,item_1);}
if((menu_1 == 3 && item_1 == 3 && Active_slot==3) || (menu_1 == 5 && item_1 == 3 && Active_slot==3)){tft.writeRectNBPP(slot1_x,slot1_y,16,114,4,item_1);}
if((menu_1 == 3 && item_1 == 3 && Active_slot==4) || (menu_1 == 5 && item_1 == 3 && Active_slot==4)){tft.writeRectNBPP(slot1_x,slot1_y,16,114,4,item_1);}
if((menu_1 == 3 && item_1 == 3 && Active_slot==5) || (menu_1 == 5 && item_1 == 3 && Active_slot==5)){tft.writeRectNBPP(slot1_x,slot1_y,16,114,4,item_1);}
if((menu_1 == 3 && item_1 == 3 && Active_slot==6) || (menu_1 == 5 && item_1 == 3 && Active_slot==6)){tft.writeRectNBPP(slot1_x,slot1_y,16,114,4,item_1);}``````

this part details the slot the item will fall into once the item is acquired. If all slots are empty use slot one, if slot one is full use slot twoâ€¦

``````
if(S1==0 && S2==0 && S3==0 && S4==0 && S5==0 && S6==0 && S7==0 && S8==0 && S9==0 && S10==0){Active_slot = 1;}
else if(S1==1 && S2==0 && S3==0 && S4==0 && S5==0 && S6==0 && S7==0 && S8==0 && S9==0 && S10==0){Active_slot = 2;}
else if(S1==1 && S2==1 && S3==0 && S4==0 && S5==0 && S6==0 && S7==0 && S8==0 && S9==0 && S10==0){Active_slot = 3;}
else if(S1==1 && S2==1 && S3==1 && S4==0 && S5==0 && S6==0 && S7==0 && S8==0 && S9==0 && S10==0){Active_slot = 4;}
else if(S1==1 && S2==1 && S3==1 && S4==1 && S5==0 && S6==0 && S7==0 && S8==0 && S9==0 && S10==0){Active_slot = 5;}
else if(S1==1 && S2==1 && S3==1 && S4==1 && S5==1 && S6==0 && S7==0 && S8==0 && S9==0 && S10==0){Active_slot = 6;}
else if(S1==1 && S2==1 && S3==1 && S4==1 && S5==1 && S6==1 && S7==0 && S8==0 && S9==0 && S10==0){Active_slot = 7;}
else if(S1==1 && S2==1 && S3==1 && S4==1 && S5==1 && S6==1 && S7==1 && S8==0 && S9==0 && S10==0){Active_slot = 8;}
else if(S1==1 && S2==1 && S3==1 && S4==1 && S5==1 && S6==1 && S7==1 && S8==1 && S9==0 && S10==0){Active_slot = 9;}
else if(S1==1 && S2==1 && S3==1 && S4==1 && S5==1 && S6==1 && S7==1 && S8==1 && S9==1 && S10==0){Active_slot = 10;}``````

Now here is the part i donâ€™t understand which is how to get he key and place it into my inventory listâ€¦

``````else      if((tft.solid[i].spritecol == cabbot) && room == 4 && Active_slot == 1 && (ButtonB.fallingEdge()) && item_1 == 1) {tft.popup(F(" ""You got an item!"" "),20); item_1 = 3, S1=1, item_loc=8, keyslot=1; return true;}
else      if((tft.solid[i].spritecol == cabbot) && room == 4 && Active_slot == 2 && (ButtonB.fallingEdge()) && item_1 == 1) {tft.popup(F(" ""You got an item!"" "),20); item_1 = 3, S2=1, item_loc=26, keyslot=2 ; return true;}
``````

what i do know is that if player collides with cabinet bottom and presses the b button it should get a pop up and place the item into inventory. i have no idea how this part works at the end.

``item_1 = 3, S1=1, item_loc=8, keyslot=1; return true;}``

if some one could help me that part i would really appreciate it. here the link for the OP.
http://legacy.gamebuino.com/forum/viewtopic.php?f=8&t=3492

First you can replace it by
int menu_x = 0;
int menu_size = 16;

You have the position y of the item with 48+(pos_menu - 1)*16
For example: pos11 = 48 + (11 - 1) * 16 = 208

the x is always 0 it seems but if you move the menu, you only have to move the position of the menu_x and menu_y

I have to go at works, but iâ€™ll try to understand your code and help for the other part of the code. You need to be abe to select 4 items in the menu, isnâ€™t it ?

yea I need the X to be 0 for each slot and the y to change. The OP has it set to a constant y and changes the x position. Thatâ€™s what this was doing on the collision part so I just set the slot_x and y manually.

``else      if((tft.solid[i].spritecol == cabbot) && room == 4 && Active_slot == 1 && (ButtonB.fallingEdge()) && item_1 == 1) {tft.popup(F(" ""You got an item!"" "),20); item_1 = 3, S1=1, slot1_x, slot1_y, return true;}``

heres what I have adapted so far. Always looking for a better way.

``````///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

if(S1==0 && S2==0 && S3==0 && S4==0 && S5==0 && S6==0 && S7==0 && S8==0 && S9==0 && S10==0){Active_slot = 1;}
else if(S1==1 && S2==0 && S3==0 && S4==0 && S5==0 && S6==0 && S7==0 && S8==0 && S9==0 && S10==0){Active_slot = 2;}
else if(S1==1 && S2==1 && S3==0 && S4==0 && S5==0 && S6==0 && S7==0 && S8==0 && S9==0 && S10==0){Active_slot = 3;}
else if(S1==1 && S2==1 && S3==1 && S4==0 && S5==0 && S6==0 && S7==0 && S8==0 && S9==0 && S10==0){Active_slot = 4;}
else if(S1==1 && S2==1 && S3==1 && S4==1 && S5==0 && S6==0 && S7==0 && S8==0 && S9==0 && S10==0){Active_slot = 5;}
else if(S1==1 && S2==1 && S3==1 && S4==1 && S5==1 && S6==0 && S7==0 && S8==0 && S9==0 && S10==0){Active_slot = 6;}
else if(S1==1 && S2==1 && S3==1 && S4==1 && S5==1 && S6==1 && S7==0 && S8==0 && S9==0 && S10==0){Active_slot = 7;}
else if(S1==1 && S2==1 && S3==1 && S4==1 && S5==1 && S6==1 && S7==1 && S8==0 && S9==0 && S10==0){Active_slot = 8;}
else if(S1==1 && S2==1 && S3==1 && S4==1 && S5==1 && S6==1 && S7==1 && S8==1 && S9==0 && S10==0){Active_slot = 9;}
else if(S1==1 && S2==1 && S3==1 && S4==1 && S5==1 && S6==1 && S7==1 && S8==1 && S9==1 && S10==0){Active_slot = 10;}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int slot1_x = 0;
int slot1_y = 48;

int slot2_x = 0;
int slot2_y = 64;

int slot3_x = 0;
int slot3_y = 80;

int slot4_x = 0;
int slot4_y = 96;

int slot5_x = 0;
int slot5_y = 112;

int slot6_x = 0;
int slot6_y = 128;

int slot7_x = 0;
int slot7_y = 144;

int slot8_x = 0;
int slot8_y = 160;

int slot9_x = 0;
int slot9_y = 176;

int slot10_x = 0;
int slot10_y = 192;

int slot11_x = 0;
int slot11_y = 208

int Active_slot;
int S1 = 0;
int S2 = 0;
int S3 = 0;
int S4 = 0;
int S5 = 0;
int S6 = 0;
int S7 = 0;
int S8 = 0;
int S9 = 0;
int S10 = 0;

int menu_1 = 1;
int item_1 = 1;
int item_2 = 1;
int item_3 = 1;
int item_4 = 1;

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

};

if((menu_1 == 3 && item_1 == 3 && Active_slot==1) || (menu_1 == 5 && item_1 == 3 && Active_slot==1)){tft.writeRectNBPP(slot1_x,slot1_y,114,16,4,item_1);}
if((menu_1 == 3 && item_1 == 3 && Active_slot==2) || (menu_1 == 5 && item_1 == 3 && Active_slot==2)){tft.writeRectNBPP(slot1_x,slot1_y,114,16,4,item_1);}
if((menu_1 == 3 && item_1 == 3 && Active_slot==3) || (menu_1 == 5 && item_1 == 3 && Active_slot==3)){tft.writeRectNBPP(slot1_x,slot1_y,114,16,4,item_1);}
if((menu_1 == 3 && item_1 == 3 && Active_slot==4) || (menu_1 == 5 && item_1 == 3 && Active_slot==4)){tft.writeRectNBPP(slot1_x,slot1_y,114,16,4,item_1);}
if((menu_1 == 3 && item_1 == 3 && Active_slot==5) || (menu_1 == 5 && item_1 == 3 && Active_slot==5)){tft.writeRectNBPP(slot1_x,slot1_y,114,16,4,item_1);}
if((menu_1 == 3 && item_1 == 3 && Active_slot==6) || (menu_1 == 5 && item_1 == 3 && Active_slot==6)){tft.writeRectNBPP(slot1_x,slot1_y,114,16,4,item_1);}
if((menu_1 == 3 && item_1 == 3 && Active_slot==7) || (menu_1 == 5 && item_1 == 3 && Active_slot==7)){tft.writeRectNBPP(slot1_x,slot1_y,114,16,4,item_1);}
if((menu_1 == 3 && item_1 == 3 && Active_slot==8) || (menu_1 == 5 && item_1 == 3 && Active_slot==8)){tft.writeRectNBPP(slot1_x,slot1_y,114,16,4,item_1);}
if((menu_1 == 3 && item_1 == 3 && Active_slot==7) || (menu_1 == 5 && item_1 == 3 && Active_slot==7)){tft.writeRectNBPP(slot1_x,slot1_y,114,16,4,item_1);}
if((menu_1 == 3 && item_1 == 3 && Active_slot==8) || (menu_1 == 5 && item_1 == 3 && Active_slot==8)){tft.writeRectNBPP(slot1_x,slot1_y,114,16,4,item_1);}
if((menu_1 == 3 && item_1 == 3 && Active_slot==9) || (menu_1 == 5 && item_1 == 3 && Active_slot==9)){tft.writeRectNBPP(slot1_x,slot1_y,114,16,4,item_1);}
if((menu_1 == 3 && item_1 == 3 && Active_slot==10) || (menu_1 == 5 && item_1 == 3 && Active_slot==10)){tft.writeRectNBPP(slot1_x,slot1_y,114,16,4,item_1);}

else      if((tft.solid[i].spritecol == cabbot) && room == 4 && Active_slot == 1 && (ButtonB.fallingEdge()) && item_1 == 1) {tft.popup(F(" ""You got an item!"" "),20); item_1 = 3, S1=1, slot1_x, slot1_y, return true;}
else      if((tft.solid[i].spritecol == cabbot) && room == 4 && Active_slot == 2 && (ButtonB.fallingEdge()) && item_1 == 1) {tft.popup(F(" ""You got an item!"" "),20); item_1 = 3, S2=1, slot2_x, slot2_y, ; return true;}
else      if((tft.solid[i].spritecol == cabbot) && room == 4 && Active_slot == 3 && (ButtonB.fallingEdge()) && item_1 == 1) {tft.popup(F(" ""You got an item!"" "),20); item_1 = 3, S3=1, slot3_x, slot3_y, return true;}
else      if((tft.solid[i].spritecol == cabbot) && room == 4 && Active_slot == 4 && (ButtonB.fallingEdge()) && item_1 == 1) {tft.popup(F(" ""You got an item!"" "),20); item_1 = 3, S4=1, slot4_x, slot4_y; return true;}
else      if((tft.solid[i].spritecol == cabbot) && room == 4 && Active_slot == 5 && (ButtonB.fallingEdge()) && item_1 == 1) {tft.popup(F(" ""You got an item!"" "),20); item_1 = 3, S5=1, slot5_x, slot5_y; return true;}
else      if((tft.solid[i].spritecol == cabbot) && room == 4 && Active_slot == 6 && (ButtonB.fallingEdge()) && item_1 == 1) {tft.popup(F(" ""You got an item!"" "),20); item_1 = 3, S6=1, slot6_x, slot6_y; return true;}
else      if((tft.solid[i].spritecol == cabbot) && room == 4 && Active_slot == 7 && (ButtonB.fallingEdge()) && item_1 == 1) {tft.popup(F(" ""You got an item!"" "),20); item_1 = 3, S7=1, slot7_x, slot7_y; return true;}
else      if((tft.solid[i].spritecol == cabbot) && room == 4 && Active_slot == 8 && (ButtonB.fallingEdge()) && item_1 == 1) {tft.popup(F(" ""You got an item!"" "),20); item_1 = 3, S8=1, slot8_x, slot8_y; return true;}
else      if((tft.solid[i].spritecol == cabbot) && room == 4 && Active_slot == 9 && (ButtonB.fallingEdge()) && item_1 == 1) {tft.popup(F(" ""You got an item!"" "),20); item_1 = 3, S9=1, slot9_x, slot9_y; return true;}
else      if((tft.solid[i].spritecol == cabbot) && room == 4 && Active_slot == 10 && (ButtonB.fallingEdge()) && item_1 == 1) {tft.popup(F(" ""You got an item!"" "),20); item_1 = 3, S10=1, slot10_x, slot10_y; return true;}

``````

thank you buy the way I appreciate the help

i donâ€™t understand the use of menu_1 that means menu_1 == 1, 3 or 5 ?

Without understanding the eal function of all that, you make your tests and do always the same thing at the end, so you can simplify your code easily. For example if you works on item you can write

if(item_1 == 3) {
if (((menu_1 == 3) || (menu_1==5)) && ('Active_slot > 0) && (Active_slot < 11)) {tft.writeRectNBPP(slot1_x,slot1_y,114,16,4,item_1);}
}

You can do same for the else section

Quoted from the op

then comes the code that actually displays/draws the menu

``````if (gb.buttons.pressed(BTN_C)){

gb.display.setColor(BLACK);
gb.display.setColor(WHITE);
gb.display.setColor(BLACK);}

else if(menu_1 >= 5){

If button C is pressed our menu_1 integer increases (for some reason this increases by 2 each time?? work in progress lol)
If its 1 it does nothing
if its 3 it displays both our BLACK and WHITE menu/inventory sprite
if it goes to 5 then it resets to 1

simply adding the above code would enable you to display a blank menu/inventory by pressing the C button on your Gamebuino whilst in the game
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Iâ€™m thinking the key integer also has something to do with the above

key_1 =1; and when picked up turns to 3

``````else      if((gb.display.solid[i].spritecol == chest) && room == 1 && Active_slot == 1 && gb.buttons.pressed(BTN_A) && key_1 == 1) {gb.popup(F(" ""You got key"" "),20); key_1 = 3, S1=1, key_loc=8, keyslot=1; return true;}
else      if((gb.display.solid[i].spritecol == chest) && room == 1 && Active_slot == 2 && gb.buttons.pressed(BTN_A) && key_1 == 1) {gb.popup(F(" ""You got key"" "),20); key_1 = 3, S2=1, key_loc=26, keyslot=2 ; return true;}
``````

I also need for each slot to hold more than one item of rhe same kind at some point

I think you can optimize this code A LOT.

For example this code:

You basically need an association table. S1, S2, S3 and S4 are booleans, so you can perform bitwise operations to create a key:
For example S1 : bit 4, S2 bit 3, S3 bit 2 and S4 bit 1.
It gives:

``````table[0x00] = 1;
table[0x08] = 2;
table[0x0c] = 3;
table[0x0e] = 4;
table[0x0f] = 0;
table[0x0a] = 2;
table[0x0b] = 2;
``````

and so forth.

Then you just need: `Active_slot = table[S1 << 4 | S2<<3 | S3<<2 | S4];`
You save A LOT of CPU instructions this way.

Iâ€™m still learning here. uh I understand this part and its just always pushing the items to an epty slotâ€¦

`` Active_slot = table[S1 << 4 | S2<<3 | S3<<2 | S4];``

But can you explain how you get the hex values in this part please?

``````table[0x00] = 1;
table[0x08] = 2;
table[0x0c] = 3;
table[0x0e] = 4;
table[0x0f] = 0;
table[0x0a] = 2;
table[0x0b] = 2;``````

I also need to shorten these as well

``````if((menu_1 == 3 && item_1 == 3 && Active_slot==1) || (menu_1 == 5 && item_1 == 3 && Active_slot==1)){tft.drawRect(slot1_x,slot1_y,81,16,BLUE); tft.setCursor(slot1_x, slot1_Y); tft.print(water);}                                                    ///{tft.writeRectNBPP(slot1_x,slot1_y,114,16,4,item_1);}
if((menu_1 == 3 && item_1 == 3 && Active_slot==2) || (menu_1 == 5 && item_1 == 3 && Active_slot==2)){tft.drawRect(slot1_x,slot1_y,81,16,BLUE); tft.setCursor(slot2_x, slot2_Y); tft.print(water);}
if((menu_1 == 3 && item_1 == 3 && Active_slot==3) || (menu_1 == 5 && item_1 == 3 && Active_slot==3)){tft.drawRect(slot1_x,slot1_y,81,16,BLUE); tft.setCursor(slot3_x, slot3_Y); tft.print(water);}
if((menu_1 == 3 && item_1 == 3 && Active_slot==4) || (menu_1 == 5 && item_1 == 3 && Active_slot==4)){tft.drawRect(slot1_x,slot1_y,81,16,BLUE); tft.setCursor(slot4_x, slot4_Y); tft.print(water);}
if((menu_1 == 3 && item_1 == 3 && Active_slot==5) || (menu_1 == 5 && item_1 == 3 && Active_slot==5)){tft.drawRect(slot1_x,slot1_y,81,16,BLUE); tft.setCursor(slot5_x, slot5_Y); tft.print(water);}
if((menu_1 == 3 && item_1 == 3 && Active_slot==6) || (menu_1 == 5 && item_1 == 3 && Active_slot==6)){tft.drawRect(slot1_x,slot1_y,81,16,BLUE); tft.setCursor(slot6_x, slot6_Y); tft.print(water);}
if((menu_1 == 3 && item_1 == 3 && Active_slot==7) || (menu_1 == 5 && item_1 == 3 && Active_slot==7)){tft.drawRect(slot1_x,slot1_y,81,16,BLUE); tft.setCursor(slot7_x, slot7_Y); tft.print(water);}
if((menu_1 == 3 && item_1 == 3 && Active_slot==8) || (menu_1 == 5 && item_1 == 3 && Active_slot==8)){tft.drawRect(slot1_x,slot1_y,81,16,BLUE); tft.setCursor(slot8_x, slot8_Y); tft.print(water);}
if((menu_1 == 3 && item_1 == 3 && Active_slot==9) || (menu_1 == 5 && item_1 == 3 && Active_slot==9)){tft.drawRect(slot1_x,slot1_y,81,16,BLUE); tft.setCursor(slot9_x, slot9_Y); tft.print(water);}
if((menu_1 == 3 && item_1 == 3 && Active_slot==10) || (menu_1 == 5 && item_1 == 3 && Active_slot==10)){tft.drawRect(slot1_x,slot1_y,81,16,BLUE); tft.setCursor(slot10_x, slot10_Y); tft.print(water);}

else      if((tft.solid[i].spritecol == cabbot) && room == 4 && Active_slot == 1 && (ButtonB.fallingEdge()) && item_1 == 1) {tft.popup(F(" ""You got an item!"" "),20); item_1 = 3, S1=1, slot1_x, slot1_y, return true;}
else      if((tft.solid[i].spritecol == cabbot) && room == 4 && Active_slot == 2 && (ButtonB.fallingEdge()) && item_1 == 1) {tft.popup(F(" ""You got an item!"" "),20); item_1 = 3, S2=1, slot2_x, slot2_y; return true;}
else      if((tft.solid[i].spritecol == cabbot) && room == 4 && Active_slot == 3 && (ButtonB.fallingEdge()) && item_1 == 1) {tft.popup(F(" ""You got an item!"" "),20); item_1 = 3, S3=1, slot3_x, slot3_y, return true;}
else      if((tft.solid[i].spritecol == cabbot) && room == 4 && Active_slot == 4 && (ButtonB.fallingEdge()) && item_1 == 1) {tft.popup(F(" ""You got an item!"" "),20); item_1 = 3, S4=1, slot4_x, slot4_y; return true;}
else      if((tft.solid[i].spritecol == cabbot) && room == 4 && Active_slot == 5 && (ButtonB.fallingEdge()) && item_1 == 1) {tft.popup(F(" ""You got an item!"" "),20); item_1 = 3, S5=1, slot5_x, slot5_y; return true;}
else      if((tft.solid[i].spritecol == cabbot) && room == 4 && Active_slot == 6 && (ButtonB.fallingEdge()) && item_1 == 1) {tft.popup(F(" ""You got an item!"" "),20); item_1 = 3, S6=1, slot6_x, slot6_y; return true;}
else      if((tft.solid[i].spritecol == cabbot) && room == 4 && Active_slot == 7 && (ButtonB.fallingEdge()) && item_1 == 1) {tft.popup(F(" ""You got an item!"" "),20); item_1 = 3, S7=1, slot7_x, slot7_y; return true;}
else      if((tft.solid[i].spritecol == cabbot) && room == 4 && Active_slot == 8 && (ButtonB.fallingEdge()) && item_1 == 1) {tft.popup(F(" ""You got an item!"" "),20); item_1 = 3, S8=1, slot8_x, slot8_y; return true;}
else      if((tft.solid[i].spritecol == cabbot) && room == 4 && Active_slot == 9 && (ButtonB.fallingEdge()) && item_1 == 1) {tft.popup(F(" ""You got an item!"" "),20); item_1 = 3, S9=1, slot9_x, slot9_y; return true;}
else      if((tft.solid[i].spritecol == cabbot) && room == 4 && Active_slot == 10 && (ButtonB.fallingEdge()) && item_1 == 1) {tft.popup(F(" ""You got an item!"" "),20); item_1 = 3, S10=1, slot10_x, slot10_y; return true;}``````

I have to repeat the bitmap part and the collision part as many times as I have menu slots for. Eventually I will need more than the ten slots. say 100, so finding away to keep from repeating each is a major concern

ok it seems we could take these two lines.

``````if((menu_1 == 3 && item_1 == 3 && Active_slot==1) || (menu_1 == 5 && item_1 == 3 && Active_slot==1)){tft.drawRect(slot1_x,slot1_y,81,16,BLUE); tft.setCursor(slot1_x, slot1_Y); tft.print(water);}                                                    ///{tft.writeRectNBPP(slot1_x,slot1_y,114,16,4,item_1);}
``````

and

``````else      if((tft.solid[i].spritecol == cabbot) && room == 4 && Active_slot == 1 && (ButtonB.fallingEdge()) && item_1 == 1) {tft.popup(F(" ""You got an item!"" "),20); item_1 = 3, S1=1, slot1_x, slot1_y, return true;}
``````

make them where they all go to slot1 and then make the table some how to always read slot 1 from the those functions but put the item in the next available slot.

that would keep me from having to point to each of the ten slots repeating the same lines of code.

ok if this part is always pushing the captured item to the next available slotâ€¦

``````
if(S1==0 && S2==0 && S3==0 && S4==0 && S5==0 && S6==0 && S7==0 && S8==0 && S9==0 && S10==0){Active_slot = 1;}
else if(S1==1 && S2==0 && S3==0 && S4==0 && S5==0 && S6==0 && S7==0 && S8==0 && S9==0 && S10==0){Active_slot = 2;}
else if(S1==1 && S2==1 && S3==0 && S4==0 && S5==0 && S6==0 && S7==0 && S8==0 && S9==0 && S10==0){Active_slot = 3;}
else if(S1==1 && S2==1 && S3==1 && S4==0 && S5==0 && S6==0 && S7==0 && S8==0 && S9==0 && S10==0){Active_slot = 4;}
else if(S1==1 && S2==1 && S3==1 && S4==1 && S5==0 && S6==0 && S7==0 && S8==0 && S9==0 && S10==0){Active_slot = 5;}
else if(S1==1 && S2==1 && S3==1 && S4==1 && S5==1 && S6==0 && S7==0 && S8==0 && S9==0 && S10==0){Active_slot = 6;}
else if(S1==1 && S2==1 && S3==1 && S4==1 && S5==1 && S6==1 && S7==0 && S8==0 && S9==0 && S10==0){Active_slot = 7;}
else if(S1==1 && S2==1 && S3==1 && S4==1 && S5==1 && S6==1 && S7==1 && S8==0 && S9==0 && S10==0){Active_slot = 8;}
else if(S1==1 && S2==1 && S3==1 && S4==1 && S5==1 && S6==1 && S7==1 && S8==1 && S9==0 && S10==0){Active_slot = 9;}
else if(S1==1 && S2==1 && S3==1 && S4==1 && S5==1 && S6==1 && S7==1 && S8==1 && S9==1 && S10==0){Active_slot = 10;}
else if(S1==1 && S2==1 && S3==1 && S4==1 && S5==1 && S6==1 && S7==1 && S8==1 && S9==1 && S10==1){Active_slot = 0;}

else if(S1==1 && S2==0 && S3==0 && S4==1 && S5==1 && S6==1 && S7==1 && S8==1 && S9==1 && S10==1){Active_slot = 2;}
else if(S1==1 && S2==0 && S3==1 && S4==0 && S5==1 && S6==1 && S7==1 && S8==1 && S9==1 && S10==1){Active_slot = 2;}
else if(S1==1 && S2==0 && S3==1 && S4==1 && S5==0 && S6==1 && S7==1 && S8==1 && S9==1 && S10==1){Active_slot = 2;}
else if(S1==1 && S2==0 && S3==1 && S4==1 && S5==1 && S6==0 && S7==1 && S8==1 && S9==1 && S10==1){Active_slot = 2;}
else if(S1==1 && S2==0 && S3==1 && S4==1 && S5==1 && S6==1 && S7==0 && S8==1 && S9==1 && S10==1){Active_slot = 2;}
else if(S1==1 && S2==0 && S3==1 && S4==1 && S5==1 && S6==1 && S7==1 && S8==0 && S9==1 && S10==1){Active_slot = 2;}
else if(S1==1 && S2==0 && S3==1 && S4==1 && S5==1 && S6==1 && S7==1 && S8==1 && S9==0 && S10==1){Active_slot = 2;}
else if(S1==1 && S2==0 && S3==1 && S4==1 && S5==1 && S6==1 && S7==1 && S8==1 && S9==1 && S10==0){Active_slot = 2;}

else if(S1==1 && S2==1 && S3==0 && S4==0 && S5==1 && S6==1 && S7==1 && S8==1 && S9==1 && S10==1){Active_slot = 3;}
else if(S1==1 && S2==1 && S3==0 && S4==1 && S5==0 && S6==1 && S7==1 && S8==1 && S9==1 && S10==1){Active_slot = 3;}
else if(S1==1 && S2==1 && S3==0 && S4==1 && S5==1 && S6==0 && S7==1 && S8==1 && S9==1 && S10==1){Active_slot = 3;}
else if(S1==1 && S2==1 && S3==0 && S4==1 && S5==1 && S6==1 && S7==0 && S8==1 && S9==1 && S10==1){Active_slot = 3;}
else if(S1==1 && S2==1 && S3==0 && S4==1 && S5==1 && S6==1 && S7==1 && S8==0 && S9==1 && S10==1){Active_slot = 3;}
else if(S1==1 && S2==1 && S3==0 && S4==1 && S5==1 && S6==1 && S7==1 && S8==1 && S9==0 && S10==1){Active_slot = 3;}
else if(S1==1 && S2==1 && S3==0 && S4==1 && S5==1 && S6==1 && S7==1 && S8==1 && S9==1 && S10==0){Active_slot = 3;}

else if(S1==1 && S2==1 && S3==1 && S4==0 && S5==0 && S6==1 && S7==1 && S8==1 && S9==1 && S10==1){Active_slot = 4;}
else if(S1==1 && S2==1 && S3==1 && S4==0 && S5==1 && S6==0 && S7==1 && S8==1 && S9==1 && S10==1){Active_slot = 4;}
else if(S1==1 && S2==1 && S3==1 && S4==0 && S5==1 && S6==1 && S7==0 && S8==1 && S9==1 && S10==1){Active_slot = 4;}
else if(S1==1 && S2==1 && S3==1 && S4==0 && S5==1 && S6==1 && S7==1 && S8==0 && S9==1 && S10==1){Active_slot = 4;}
else if(S1==1 && S2==1 && S3==1 && S4==0 && S5==1 && S6==1 && S7==1 && S8==1 && S9==0 && S10==1){Active_slot = 4;}
else if(S1==1 && S2==1 && S3==1 && S4==0 && S5==1 && S6==1 && S7==1 && S8==1 && S9==1 && S10==0){Active_slot = 4;}

else if(S1==1 && S2==1 && S3==1 && S4==1 && S5==0 && S6==0 && S7==1 && S8==1 && S9==1 && S10==1){Active_slot = 5;}
else if(S1==1 && S2==1 && S3==1 && S4==1 && S5==0 && S6==1 && S7==0 && S8==1 && S9==1 && S10==1){Active_slot = 5;}
else if(S1==1 && S2==1 && S3==1 && S4==1 && S5==0 && S6==1 && S7==1 && S8==0 && S9==1 && S10==1){Active_slot = 5;}
else if(S1==1 && S2==1 && S3==1 && S4==1 && S5==0 && S6==1 && S7==1 && S8==1 && S9==0 && S10==1){Active_slot = 5;}
else if(S1==1 && S2==1 && S3==1 && S4==1 && S5==0 && S6==1 && S7==1 && S8==1 && S9==1 && S10==0){Active_slot = 5;}

else if(S1==1 && S2==1 && S3==1 && S4==1 && S5==1 && S6==0 && S7==0 && S8==1 && S9==1 && S10==1){Active_slot = 6;}
else if(S1==1 && S2==1 && S3==1 && S4==1 && S5==1 && S6==0 && S7==1 && S8==0 && S9==1 && S10==1){Active_slot = 6;}
else if(S1==1 && S2==1 && S3==1 && S4==1 && S5==1 && S6==0 && S7==1 && S8==1 && S9==0 && S10==1){Active_slot = 6;}
else if(S1==1 && S2==1 && S3==1 && S4==1 && S5==1 && S6==0 && S7==1 && S8==1 && S9==1 && S10==0){Active_slot = 6;}

else if(S1==1 && S2==1 && S3==1 && S4==1 && S5==1 && S6==1 && S7==0 && S8==0 && S9==1 && S10==1){Active_slot = 7;}
else if(S1==1 && S2==1 && S3==1 && S4==1 && S5==1 && S6==1 && S7==0 && S8==1 && S9==0 && S10==1){Active_slot = 7;}
else if(S1==1 && S2==1 && S3==1 && S4==1 && S5==1 && S6==1 && S7==0 && S8==1 && S9==1 && S10==0){Active_slot = 7;}

else if(S1==1 && S2==1 && S3==1 && S4==1 && S5==1 && S6==1 && S7==1 && S8==0 && S9==0 && S10==1){Active_slot = 8;}
else if(S1==1 && S2==1 && S3==1 && S4==1 && S5==1 && S6==1 && S7==1 && S8==0 && S9==1 && S10==0){Active_slot = 8;}

else if(S1==1 && S2==1 && S3==1 && S4==1 && S5==1 && S6==1 && S7==1 && S8==1 && S9==0 && S10==0){Active_slot = 9;}``````

â€¦then couldnâ€™t I make a structure for each slot to give its onscreen coordinates then call it always as active slot=1. Something likeâ€¦

``````struct S1{
int16_t x;
int16_t y;
uint8_t width;
uint8_t height;
};``````

S1 : bit 4 (0x08), S2 bit 3 (0x04), S3 bit 2 (0x02) and S4 bit 1 (0x01).

S1==0 && S2==0 && S3==0 && S4==0
=> 0 * 0x08 + 0 * 0x04 + 0 * 0x02 + 0 * 0x01 = 0x00

S1==1 && S2==0 && S3==0 && S4==0
=> 1 * 0x08 + 0 * 0x04 + 0 * 0x02 + 0 * 0x01 = 0x08

S1==1 && S2==1 && S3==0 && S4==0
=> 1 * 0x08 + 1 * 0x04 + 0 * 0x02 + 0 * 0x01 = 0x0c

S1==1 && S2==1 && S3==1 && S4==0
=> 1 * 0x08 + 1 * 0x04 + 1 * 0x02 + 0 * 0x01 = 0x0e

etc.

However looking at the global problem, the problem seems much deeper. I really have to continue my coding guide. The overall idea is to separate well data and its representation (on the screen for example), and its manipulation (either from input or automatic updates).