Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: glurex on Mon 06/02/2023 04:41:46

Title: Specific sound on inventory buttons
Post by: glurex on Mon 06/02/2023 04:41:46
Hi everybody!

It's kinda hard to explain, at least to me... But here we go:

I have an inventory that displays four inventory items "per page". This inventory has two buttons for scrolling purposes (the classical btnInvUp and btnInvDown). I have asigned a sound to each one so when I click one of them it sounds a scroll sound.

(https://i.ibb.co/ZXLYJqf/Imagen4.png)

But I want to play a sound (scroll sound) when there is more items in the next "page" to show and another sound when there isn't more items (stuck sound). Similar case when I have less than 4 items, it should sound "stuck" in both ("<" and ">") buttons. But if I have, for example, 5 items it should sound stuck in "<" and sound scroll when I click on ">" because there is a new "page" with one item.

For example in this scenario, if I click the right btnInvDown (>) it must sound a "stuck sound" because there isn't enough items:

(https://i.ibb.co/MC2z9W1/Imagen5.png)

I belive I have to code with "InvWindow functions and properties", and "ItemCount"/"ItemsPerRow"/"RowCount". But I have not find the right way to do that. Bearing in mind I don't know yet how many inv items my game will have.

Many thanks!
Title: Re: Specific sound on inventory buttons
Post by: Khris on Mon 06/02/2023 10:53:26
You can use this:
  // inside the button's OnClick function
  int ti = invWindow.TopItem;
  invWindow.ScrollDown();
  if (ti == invWindow.TopItem) aInvStuck.Play();
  else aScrollInv.Play();

edit: fixed code
Title: Re: Specific sound on inventory buttons
Post by: Matti on Mon 06/02/2023 11:30:36
On a side note: As a player I find it convenient if the arrow buttons already indicate that there are no more items in one direction.
Title: Re: Specific sound on inventory buttons
Post by: glurex on Mon 06/02/2023 18:07:19
Quote from: Khris on Mon 06/02/2023 10:53:26You can use this

Thanks for your time, Khris. But it's weird. I write the code inside the function as you said:

function btnInvDown_OnClick(GUIControl *control, MouseButton button)
{   
     InventoryItem* ii = invCustom.TopItem;
  invCustom.ScrollDown();
  if (ii == invCustom.TopItem) aStuck.Play();
  else aScroll.Play();
}

and I get this error:

GlobalScript.asc(534): Error (line 534): Type mismatch: cannot convert 'int' to 'InventoryItem*'

I'm confusing about what is happening to get the Type mismatch: cannot convert 'int' to 'InventoryItem*' error  :-\

Quote from: Matti on Mon 06/02/2023 11:30:36On a side note: As a player I find it convenient if the arrow buttons already indicate that there are no more items in one direction.

Yes, it's a very good idea too. Thanks  :)
Title: Re: Specific sound on inventory buttons
Post by: Khris on Mon 06/02/2023 21:33:34
Yeah, my bad; .TopItem is an integer. I fixed the code in my post :)
Title: Re: Specific sound on inventory buttons
Post by: glurex on Mon 06/02/2023 21:38:04
Quote from: Khris on Mon 06/02/2023 21:33:34Yeah, my bad; .TopItem is an integer. I fixed the code in my post :)

Thanks Khris! It works like a charm!  :)

Now that you said it, it makes sense that .TopItem is an integer.