on_event issues with blocking.

Started by markbilly, Sat 07/08/2010 18:47:34

Previous topic - Next topic

markbilly

I'm using this bit of script:

Code: ags

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?
 

Dualnames

Quote from: markbilly on Sat 07/08/2010 18:47:34
I'm using this bit of script:

Code: ags

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.
Worked on Strangeland, Primordia, Hob's Barrow, The Cat Lady, Mage's Initiation, Until I Have You, Downfall, Hunie Pop, and every game in the Wadjet Eye Games catalogue (porting)

markbilly

Or go through my whole script adding PlaySound() where applicable. I'm just too lazy, though... ;)
 

Khris

I'd use a function, like this:

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

Ryan Timothy B

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

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



Which would replace the default AGS AddInventory, with this:
Code: ags

player.AddInventoryWithSound(iWhatever);


His would also not work with hotspots or if a character handed it to you, etc.

markbilly

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!
 

Khris

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.

SMF spam blocked by CleanTalk