Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: .M.M. on Fri 21/03/2008 08:05:41

Title: Don´t understant to on_event
Post by: .M.M. on Fri 21/03/2008 08:05:41
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?
Title: Re: Don´t understant to on_event
Post by: Dualnames on Fri 21/03/2008 09:12:07
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.
Title: Re: Don´t understant to on_event
Post by: Khris on Fri 21/03/2008 10:46:23
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:

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!");
  }
}
Title: Re: Don´t understant to on_event
Post by: .M.M. on Fri 21/03/2008 16:43:53
Thank you both for sloving my problem! :D
KhrisMUC- I did not fugure out how to do it on_event(eEventAddInventory, -1); but  thanks to that I did it in another way. Again, thank you very much!
Title: Re: Don´t understant to on_event
Post by: Khris on Fri 21/03/2008 18:39:41
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()).
Title: Re: Don´t understant to on_event
Post by: .M.M. on Sat 22/03/2008 13:43:12
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