Specific sound on inventory buttons

Started by glurex, Mon 06/02/2023 04:41:46

Previous topic - Next topic

glurex

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.



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:



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!

Khris

#1
You can use this:
Code: ags
  // inside the button's OnClick function
  int ti = invWindow.TopItem;
  invWindow.ScrollDown();
  if (ti == invWindow.TopItem) aInvStuck.Play();
  else aScrollInv.Play();

edit: fixed code

Matti

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.

glurex

#3
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:

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

Khris

Yeah, my bad; .TopItem is an integer. I fixed the code in my post :)

glurex

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.

SMF spam blocked by CleanTalk