Wheel North South selecting Inventory Item problem.

Started by Dualnames, Fri 09/03/2007 21:05:16

Previous topic - Next topic

Dualnames

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.
Worked on Strangeland, Primordia, Hob's Barrow, The Cat Lady, Mage's Initiation, Until I Have You, Downfall, Hunie Pop, and every game in the Wadjet Eye Games catalogue (porting)

Khris

This will cycle through the inventory items in the order they appear in AGSEdit:

Code: ags
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);
  ...

Ashen

You could also use InvWindow.ItemAtIndex and InvWindow.ItemCount to scroll through them in the order they're in your inventory:
Code: ags

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.
I know what you're thinking ... Don't think that.

Dualnames

Worked on Strangeland, Primordia, Hob's Barrow, The Cat Lady, Mage's Initiation, Until I Have You, Downfall, Hunie Pop, and every game in the Wadjet Eye Games catalogue (porting)

SMF spam blocked by CleanTalk