Scrolling Inventory

Started by monkey0506, Fri 01/10/2004 02:27:23

Previous topic - Next topic

monkey0506

For my scrolling inventory, I want the arrow buttons to ONLY be on if you can scroll the inventory in that direction. So, I made the following function which I call in repeatedly_execute():

Code: ags
function Inventory(){
Ã,  if (GetButtonPic(MAIN, 11, 1)==0) SetGUIObjectEnabled(MAIN, 11, 0);
Ã,  else SetGUIObjectEnabled(MAIN, 11, 1);
Ã,  if (GetButtonPic(MAIN, 12, 1)==0) SetGUIObjectEnabled(MAIN, 12, 0);
Ã,  else SetGUIObjectEnabled(MAIN, 12, 1);
Ã,  if (game.num_inv_items<=8){
Ã,  Ã,  SetButtonPic(MAIN, 11, 1, 0);
Ã,  Ã,  SetButtonPic(MAIN, 12, 1, 0);
Ã,  Ã,  }
Ã,  else if (game.num_inv_items>8){
Ã,  Ã,  if (game.top_inv_item==1){
Ã,  Ã,  Ã,  SetButtonPic(MAIN, 11, 1, 0);
Ã,  Ã,  Ã,  SetButtonPic(MAIN, 12, 1, 0);
Ã,  Ã,  Ã,  }
Ã,  Ã,  else if (game.num_inv_items<=game.top_inv_item+7){
Ã,  Ã,  Ã,  SetButtonPic(MAIN, 11, 1, 13);
Ã,  Ã,  Ã,  SetButtonPic(MAIN, 12, 1, 0);
Ã,  Ã,  Ã,  }
Ã,  Ã,  else if (game.num_inv_items>game.top_inv_item+7){
Ã,  Ã,  Ã,  SetButtonPic(MAIN, 11, 1, 13);
Ã,  Ã,  Ã,  SetButtonPic(MAIN, 12, 1, 14);
Ã,  Ã,  Ã,  }
Ã,  Ã,  }
Ã,  }


It works, except if the number of inventory items is <=8 at the start of the game, it takes a second to turn off the buttons. Nevermind, I fixed this by moving this function before game_start(), and calling it there so when the first room loads it has already checked the inventory. My other problem is that if the inventory is scrolled all the way to the top, the up arrow, button 11, should have it's image set to 0, but it isn't. If num_inv_items<=8, both buttons 11 and 12 are off. If num_inv_items==9 (for example), both buttons are on when I scroll to the very top of the inventory box, but the down button (12) is off when I scroll to the very bottom of the inventory. I'm sorry if this is confusing...

EDIT: I think it may have to do with the line:

Code: ags
if (game.top_inv_item==1)


But I'm not sure what to use to check if the inventory is scrolled all the way to the top...

EDIT: I appear to have posted too soon:

Code: ags
function Inventory(){
Ã,  if (GetButtonPic(MAIN, 11, 1)==0) SetGUIObjectEnabled(MAIN, 11, 0);
Ã,  else SetGUIObjectEnabled(MAIN, 11, 1);
Ã,  if (GetButtonPic(MAIN, 12, 1)==0) SetGUIObjectEnabled(MAIN, 12, 0);
Ã,  else SetGUIObjectEnabled(MAIN, 12, 1);
Ã,  if (game.num_inv_items<=8){
Ã,  Ã,  SetButtonPic(MAIN, 11, 1, 0);
Ã,  Ã,  SetButtonPic(MAIN, 12, 1, 0);
Ã,  Ã,  }
Ã,  else if (game.num_inv_items>8){
Ã,  Ã,  if (game.num_inv_items<=game.top_inv_item+7){
Ã,  Ã,  Ã,  SetButtonPic(MAIN, 11, 1, 13);
Ã,  Ã,  Ã,  SetButtonPic(MAIN, 12, 1, 0);
Ã,  Ã,  Ã,  }
Ã,  Ã,  else if (game.num_inv_items>game.top_inv_item+7){
Ã,  Ã,  Ã,  if (game.top_inv_item<4){
Ã,  Ã,  Ã,  Ã,  SetButtonPic(MAIN, 11, 1, 0);
Ã,  Ã,  Ã,  Ã,  SetButtonPic(MAIN, 12, 1, 14);
Ã,  Ã,  Ã,  Ã,  }
Ã,  Ã,  Ã,  else{
Ã,  Ã,  Ã,  Ã,  SetButtonPic(MAIN, 11, 1, 13);
Ã,  Ã,  Ã,  Ã,  SetButtonPic(MAIN, 12, 1, 14);
Ã,  Ã,  Ã,  Ã,  }
Ã,  Ã,  Ã,  }
Ã,  Ã,  }
Ã,  }


Works like a charm...

TerranRich

Hah, excellent. I could personally use this code, so I will be keeping this thread here. :)
Status: Trying to come up with some ideas...

monkey0506

#2
Heh. Well I'm sorry for once again posting when I really didn't need to, but I feel AMAZED(!) (:o :o :o :o) That I, of all people, helped the Great QuantumRich. In case you couldn't tell, my inventory has four items on each line, with eight items displayed at a time, button 11 is the up arrow, and button 12 is the down arrow. I disabled the buttons so that if they aren't on, they can't be clicked, because you wouldn't want to scroll through the inventory if there's nothing to scroll through, now would you?*

* - I find this to be a very practical question, and don't really care if you disagree with me. If you want to be able to scroll through your empty inventory, you need to get a life. Nerd.**

**- J/k...

EDIT: Also, in case you missed the part about game_start(), I called this function in game_start() so that it would update the button pictures before the first room is loaded because other wise it would take a while to reach the point in the script where it changes them...

TerranRich

Yes, and that's something (putting it in game_start) that I would've figure out on my own after much trial & error. :)
Status: Trying to come up with some ideas...

monkey0506

#4
Wow... Do you know how good that makes me feel? I know it's something small and insignificant, but I'm serious. I've been having suicidal thoughts lately (no joke), and I've just been really depressed. I can't take it any more. But that makes me feel really good. To know that I helped you overcome even such a trivial problem... I don't see the point in living any more, but, I don't want to kill myself. I don't really want to die, but I'd just like to ask any Christian members to pray for me. I can't take this. I need this load lifted off of me, or I don't know what I'm going to do.

EDIT: I commented the code last night...

Code: ags
function InventoryArrows(){//handles the inventory scroll arrows
Ã,  if (GetButtonPic(MAIN, 11, 1)==0) SetGUIObjectEnabled(MAIN, 11, 0);//if the up arrow is off, disable it
Ã,  else SetGUIObjectEnabled(MAIN, 11, 1);//otherwise, enable it
Ã,  if (GetButtonPic(MAIN, 12, 1)==0) SetGUIObjectEnabled(MAIN, 12, 0);//if the down arrow is off, disable it
Ã,  else SetGUIObjectEnabled(MAIN, 12, 1);//otherwise enable it
Ã,  if (game.num_inv_items<=8){//if the player has less than 9 items
Ã,  Ã,  SetButtonPic(MAIN, 11, 1, 0);//turn button 11 (up arrow) off
Ã,  Ã,  SetButtonPic(MAIN, 12, 1, 0);//turn button 12 (down arrow) off
Ã,  Ã,  }
Ã,  else if (game.num_inv_items>8){//if the player has more than 8 items
Ã,  Ã,  if (game.num_inv_items<=game.top_inv_item+7){//if reached bottom of inventory window
Ã,  Ã,  Ã,  SetButtonPic(MAIN, 11, 1, 13);//turn button 11 on
Ã,  Ã,  Ã,  SetButtonPic(MAIN, 12, 1, 0);//turn button 12 off
Ã,  Ã,  Ã,  }
Ã,  Ã,  else if (game.num_inv_items>game.top_inv_item+7){//if has not reached bottom of inventory window
Ã,  Ã,  Ã,  if (game.top_inv_item<4){//if reached top of inventory window
Ã,  Ã,  Ã,  Ã,  SetButtonPic(MAIN, 11, 1, 0);//turn button 11 off
Ã,  Ã,  Ã,  Ã,  SetButtonPic(MAIN, 12, 1, 14);//turn button 12 on
Ã,  Ã,  Ã,  Ã,  }
Ã,  Ã,  Ã,  else{//if has not reached top or bottom of inventory window
Ã,  Ã,  Ã,  Ã,  SetButtonPic(MAIN, 11, 1, 13);//turn button 11 on
Ã,  Ã,  Ã,  Ã,  SetButtonPic(MAIN, 12, 1, 14);//turn button 12 on
Ã,  Ã,  Ã,  Ã,  }
Ã,  Ã,  Ã,  }
Ã,  Ã,  }
Ã,  }


I also added Arrows to the function's name...

SMF spam blocked by CleanTalk