Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: SirLean on Wed 26/07/2023 18:51:09

Title: No sound when interacting with inventory object
Post by: SirLean on Wed 26/07/2023 18:51:09
So my idea is that basically a sound is played when I click (interact mode) on an inventory object. I add the

"Sound.Play();"

code but absolutely nothing plays. I tried with other click modes and it plays (like for example "Look at") but my idea is that the sound is played when the cursor changes into the object and it's "grabbed".

Thanks!  :)
Title: Re: No sound when interacting with inventory object
Post by: Nahuel on Wed 26/07/2023 19:01:50
Actually, the name of the file (ScriptName) should be used there. Did you import the audio/sfx file?

Depending on the type, you can import music, ambient or sound.

(https://i.ibb.co/9VkknTs/Screenshot-2023-07-26-at-20-02-31.png)

On your code you need to (normally it adds a.... at the beginning of the file name) so:

aWaterfall.Play(eAudioPriorityNormal);
and you can give the priority depending on your need.

Hope it helps  :)

EDIT: added image.
Title: Re: No sound when interacting with inventory object
Post by: SirLean on Wed 26/07/2023 20:48:27
yeah, I did that but doesn't play a sound. Not normal sound, not music, nothing.

ummm can I ask you to try it for yourself to see if you can interact and make it play some sound?

 That way we'll corroborate if that's a problem only I have or if it's an issue that could be notified to the AGS high rank programmers.
Title: Re: No sound when interacting with inventory object
Post by: Nahuel on Wed 26/07/2023 21:01:36
Are you 100% sure that when you do the action needed, the code is being hit?

I would suggest to add a breakpoint on that line.
Secondly if that line is hit and no sound; Are you sure that the file was correctly imported and it contains the actual sound and it's not empty?

Which AGS version are you working with? Which template?

I'm currently working on some POCs and I'm actually even using Tween Module (awesome) module for FadeOut

    AudioChannel *humming;
    humming = aHumming.Play(eAudioPriorityNormal, eRepeat);
    aWater_drop.Play();

    // [more code]
    humming.TweenFadeOut(1.5, eEaseLinearTween);


EDIT: This works just fine using VerbCoins


AGS Editor .NET (Build 3.6.0.48)
v3.6.0, May 2023


(https://i.ibb.co/pXKgRwx/Screenshot-2023-07-26-at-22-11-36.png)

function iCup_Look()
{
  aWater_drop.Play();
}
Title: Re: No sound when interacting with inventory object
Post by: Crimson Wizard on Thu 27/07/2023 00:03:15
Quote from: SirLean on Wed 26/07/2023 18:51:09I tried with other click modes and it plays (like for example "Look at")

Of course there's no relation between a click mode and a sound playing or not playing.

If exactly same command works in one click mode but not another, then something is wrong with the click mode. So focus on that instead.

Replace the Sound.Play with a more common function, like Display, and see if it works. If it does not, that would mean that the interaction itself is not run.

Do "Interact" clicks work in other cases, for other objects in your game?
If yes, then double check that you have this particular "object_Interact" function name in the object's event table.
If no, then this is a problem with how your on_mouse_click is scripted. Which game template do you use?
Title: Re: No sound when interacting with inventory object
Post by: SirLean on Thu 27/07/2023 00:44:49
I'm using the blank template. AGS 3.6.

I'll keep trying...
Title: Re: No sound when interacting with inventory object
Post by: Khris on Thu 27/07/2023 08:09:02
If your game is still set to default inv click handling, AGS never runs the "interact with inventory" handler, it simply makes the item active and that's it.

Since using custom inv click handling just to play a sound seems like overkill, you can instead track the mouse Mode:

// above repeatedy_execute in Global Script
bool item_was_held;

  // inside repeatedy_execute
  item_is_held = mouse.Mode == eModeUseinv && player.ActiveInventory != null;
  if (item_is_held && !item_was_held) aPickup.Play();
  item_was_held = item_is_held;
Title: Re: No sound when interacting with inventory object
Post by: SirLean on Thu 27/07/2023 23:36:55
Thanks Khris, is that code to make every click on any inventory item play the same sound?

My idea is that every inventory item should have a personalized sound
Title: Re: No sound when interacting with inventory object
Post by: Khris on Thu 27/07/2023 23:57:26
In that case you can replace line 6 with
  if (item_is_held && !item_was_held) {
    if (player.ActiveInventory == iBook) aPickupBook.Play();
    if (player.ActiveInventory == iBottle) aPickupBottle.Play();
    // etc.
  }