Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Dualnames on Fri 09/03/2007 21:05:16

Title: Wheel North South selecting Inventory Item problem.
Post by: Dualnames on Fri 09/03/2007 21:05:16
Well, it is quite simple. I want to use them to cycle through my inventory items.
ATTENTION not through my inventory I can do that. I need to use the wheel to cycle my items.
Title: Re: Wheel North South problem.
Post by: Khris on Sat 10/03/2007 15:04:51
This will cycle through the inventory items in the order they appear in AGSEdit:

function inv_scroll(bool down) {
  InventoryItem*item=player.ActiveInventory;
  if (item==null) return;
  int i=item.ID;
  int ni=0;
  while(ni==0) {
    if (down) i++;
    else i--;
    if (i>Game.InventoryItemCount) i=1;
    if (i<1) i=Game.InventoryItemCount;
    if (player.InventoryQuantity[i]>0) ni=i;
  }
  player.ActiveInventory=inventory[ni];
}

// on_mouse_click
  ...
  else if (button==eMouseWheelNorth) inv_scroll(false);
  else if (button==eMouseWheelSouth) inv_scroll(true);
  ...
Title: Re: Wheel North South problem.
Post by: Ashen on Sat 10/03/2007 16:05:20
You could also use InvWindow.ItemAtIndex and InvWindow.ItemCount to scroll through them in the order they're in your inventory:

int i; // declare outside of function
function inv_scroll(bool down) {
  if (down) i --;
  else i++;
  if (i < 0) i = invCustomInv.ItemCount - 1;
  if (i >= invCustomInv.ItemCount) i = 0;
  player.ActiveInventory = invCustomInv.ItemAtIndex[i];
}

// on_mouse_click bit stays the same


I don't think there's any practical difference, this is just a little shorter as it skips the need to chack if the player has the item.
Title: Re: Wheel North South problem.
Post by: Dualnames on Mon 12/03/2007 20:52:54
Gee thanks buddy.