Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: markbilly on Sat 07/08/2010 18:47:34

Title: on_event issues with blocking.
Post by: markbilly on Sat 07/08/2010 18:47:34
I'm using this bit of script:


function on_event(int event, int data) {

if (event == eEventAddInventory) PlaySound(50);
}


...to play a sound when the player picks up an item.

The problem is, it doesn't like being blocked so the sound ends up playing after the 'pick up' animation has finished.

Any ideas on making this a function (or event) impervious to blocking?
Title: Re: on_event issues with blocking.
Post by: Dualnames on Sat 07/08/2010 18:53:08
Quote from: markbilly on Sat 07/08/2010 18:47:34
I'm using this bit of script:


function on_event(int event, int data) {

if (event == eEventAddInventory) PlaySound(50);
}


...to play a sound when the player picks up an item.

The problem is, it doesn't like being blocked so the sound ends up playing after the 'pick up' animation has finished.

Any ideas on making this a function (or event) impervious to blocking?

If I assume there's a pick up animation there are two ways, have the item lose before the animation, or use animation run script module. But the last is a far-fetch really.
Title: Re: on_event issues with blocking.
Post by: markbilly on Sat 07/08/2010 18:57:25
Or go through my whole script adding PlaySound() where applicable. I'm just too lazy, though... ;)
Title: Re: on_event issues with blocking.
Post by: Khris on Sat 07/08/2010 19:24:01
I'd use a function, like this:

void PickUp(Object*o, InventoryItem*i) {
  // animate
  PlaySound(50);
  if (o != null) o.Visible = false;
  if (i != null) player.AddInventory(i);
}


Then: PickUp(oPen, iPen);

You'd still have to replace all the current lines though, of course.
Title: Re: on_event issues with blocking.
Post by: Ryan Timothy B on Sat 07/08/2010 19:33:51
Going Khris' route would mean that you'd have to have the animations for each animation type and such scripted within his PickUp function.

I'd simply go this route:

void AddInventoryWithSound(this Character*, InventoryItem *item)
{
  PlaySound(50);
  this.AddInventory(item);
}



Which would replace the default AGS AddInventory, with this:

player.AddInventoryWithSound(iWhatever);


His would also not work with hotspots or if a character handed it to you, etc.
Title: Re: on_event issues with blocking.
Post by: markbilly on Sat 07/08/2010 20:25:32
That's a good solution, I was thinking of writing an alternative function...

Then, although I will have to replace all that I have now, at least I won't have to remember the sound for future scripting.

Cheers!
Title: Re: on_event issues with blocking.
Post by: Khris on Sat 07/08/2010 23:40:16
Quote from: Ryan Timothy on Sat 07/08/2010 19:33:51
His would also not work with hotspots or if a character handed it to you, etc.

In the case of these, simply pass null as the first parameter.