Don´t understant to on_event

Started by .M.M., Fri 21/03/2008 08:05:41

Previous topic - Next topic

.M.M.

Hi, I want to every time player will have new item, game do something (for example Display command). But how to do that better than script on_event for every item? This is what manual says:
eEventAddInventory
      the player just got a new inventory item
      DATA = inventory item number that was added
But I need to DATA will be every items!  :P
And, also, I have Journal module (http://www.adventuregamestudio.co.uk/yabb/index.php?topic=27158.0)- how to on_event  for each new record in journal?

Dualnames

I think that works the following way:
if ((event==eEventAddInventory) && (DATA==sandwich.ID)) {
//code
}

sandwich is an inventory item..

About the Journal Module.. that beats me.
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)

Khris

Yes, the thing is that you don't have to script it for every item because that's precisely what on_event is meant for: to react very time a specific event takes place.
It's like this: every time an inventory item is added, AGS tries to call on_event(eEventAddInventory, added_item.ID);

As soon as you define that function, it gets called automatically. If you want something to happen for every new journal entry, too, you can call the function manually.
So in the journal module, look for the piece of code that's executed whenever a new entry is added, then put on_event(eEventAddInventory, -1); or something similar in there.

Then, in the global script, add the function:

Code: ags
function on_event(Event e, int data) {
  if (e == eEventAddInventory) {
    if (data > 0) Display("You got a %s!", inventory[data].Name);
    else Display("You've added a new entry to your journal!");
  }
}

.M.M.

Thank you both for sloving my problem! :D
KhrisMUC- I did not fugure out how to do it
Code: ags
 on_event(eEventAddInventory, -1); 
but  thanks to that I did it in another way. Again, thank you very much!

Khris

You're welcome :)
Btw, I think you have to import the on_event function in the module's header to be able to call it from the module.
Although, thinking about it, it might not be possible at all to call a function from the global script in a module. (As a workaround, one could move the code to a custom on_event function in or above the module, then call that from both the module and inside on_event()).

.M.M.

I created new item called "Journal", and every time player have new entry, he got this item.If player has more than one, AGS will delete it (one of Journals).    ;D

SMF spam blocked by CleanTalk