Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Slasher on Wed 14/05/2014 22:18:01

Title: Inventory item count and Scroll...
Post by: Slasher on Wed 14/05/2014 22:18:01
Hi,

I am trying to re-script around this piece of script.

Code (ags) Select

void on_event(EventType event, int data) {

  if (event == eEventLoseInventory) {
    int ic = InventoryWindow3.ItemCount;
    //invCustomInv.ItemCount;
    if ((ic/6)*6 == ic && InventoryWindow3.TopItem == ic-6)

InventoryWindow3.ScrollUp();
}
  if(event == eEventAddInventory && mouse.Mode == eModeWalkto)
{
  mouse.Mode = eModeInteract;


My Inventory window has one column showing 6 items at a time, if bottom one is used I want the window to scroll up. Would you assist me please.. Without having to put TopItem in every room.

cheers


Title: Re: Inventory item count and Scroll...
Post by: Khris on Thu 15/05/2014 00:31:53
I tested this and it looks like TopItem isn't updated in this special case, meaning it will still point to the item index that has just been removed.
Which means all that should be necessary in order to fix this is to change "== ic-6" to "== ic".

Btw, a more future-proof solution is to replace all sixes with InventoryWindow3.ItemsPerRow, altough this won't hold up when you decide to make the InvWindow more than one row tall.

One catch-all method I used in the past is to calculate the coordinates of the leftmost item slot in the bottom row, then check whether InventoryItem.GetAtScreenXY returns null there.