No sound when interacting with inventory object

Started by SirLean, Wed 26/07/2023 18:51:09

Previous topic - Next topic

SirLean

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!  :)

Nahuel

#1
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.



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

Code: ags
aWaterfall.Play(eAudioPriorityNormal);

and you can give the priority depending on your need.

Hope it helps  :)

EDIT: added image.
Life isn't a game. Let's develop a life-like-game.

SirLean

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.

Nahuel

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

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




Code: ags
function iCup_Look()
{
  aWater_drop.Play();
}
Life isn't a game. Let's develop a life-like-game.

Crimson Wizard

#4
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?

SirLean

I'm using the blank template. AGS 3.6.

I'll keep trying...

Khris

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:

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

SirLean

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

Khris

In that case you can replace line 6 with
Code: ags
  if (item_is_held && !item_was_held) {
    if (player.ActiveInventory == iBook) aPickupBook.Play();
    if (player.ActiveInventory == iBottle) aPickupBottle.Play();
    // etc.
  }

SMF spam blocked by CleanTalk