Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: randypana on Sat 06/07/2013 00:46:17

Title: PROBLEM WITH MY GAME
Post by: randypana on Sat 06/07/2013 00:46:17
PROBLEM WITH MY GAME
HELLO I WAS MAKING PREPARATIONS FOR ME STEP MY GAME AND A DOUBT:
IN MY GAME THE CHARACTER OBJECTS HAVE AN INVENTORY AND THEN I HAVE TO DO TO OBJECT TO JOIN WITH OTHER OBJECTS OF INVENTORY TO INTERACTIONS OR PUT MESSAGES, BUT I THINK I WOULD HAVE TO PUT A LOT OF DIALOGUES EQUAL WORK COULD SAVE ME DO THAT
Title: Re: PROBLEM WITH MY GAME
Post by: Armageddon on Sat 06/07/2013 03:18:05
STOP YELLING! And please try to re-articulate your sentence it's hard to understand the problem.
Title: Re: PROBLEM WITH MY GAME
Post by: Khris on Sat 06/07/2013 09:22:55
It kind of sounds like you're looking for unhandled_event?
http://www.adventuregamestudio.co.uk/manual/ags42.htm#textscriptevents, bottom of the page.
Title: Re: PROBLEM WITH MY GAME
Post by: randypana on Sat 06/07/2013 18:50:21
Quote from: Khris on Sat 06/07/2013 09:22:55
It kind of sounds like you're looking for unhandled_event?
http://www.adventuregamestudio.co.uk/manual/ags42.htm#textscriptevents, bottom of the page.
Thanks that was what I was looking for someone could explain the script: On Event and unhandled_event.
Title: Re: PROBLEM WITH MY GAME
Post by: monkey0506 on Sat 06/07/2013 19:13:12
on_event is a built-in event handler that can appear in any script file (except a dialog script file) (and not an ASH script header, which is different). You have to type it yourself from scratch (unless the template you used already created it), the editor won't create it for you. It is specifically designed to handle certain in-game events in a generic fashion. For example, eEventEnterRoomBeforeFadein allows you to specify what happens whenever the player enters any room:

Code (ags) Select
function on_event(EventType event, int data)
{
  if (event == eEventEnterRoomBeforeFadein)
  {
    player.PlaceOnWalkableArea();
  }
}


This will ensure that no matter where the player enters the room, they will always be on a walkable area when the room fades in. It's better to use the right coordinates yourself, but this can be a good safety precaution if your walkable areas change for some reason.

AGS also has item-specific event handlers for individual Characters, Hotspots, Objects, Rooms, GUIs, etc. These are not built-in, and can only be placed in the GlobalScript.asc. You should create these handlers by opening the tab for the Character (or other entity) that you want, and then clicking on the lightning-bolt shaped icon in the Properties pane (at the lower side of the column on the right). This will show you the available events. For example, Characters can have an "Any click" handler, and then handlers based on the mouse cursor modes, "Interact", "Look at", etc. If you click the (empty) text box next to the event you want (say, Interact) then a button will appear with "...". By clicking on that button you will create the handler in the global script, and it will open to that event so you can type in your own code:

Code (ags) Select
function cEgo_Interact()
{
  cEgo.Say("Yup, still got my nipples.");
}


Finally, there is unhandled_event. This is another built-in handler (you have to type it in yourself), but it will only be called if the interaction the player selected doesn't have a specified handler. For Characters, if there is an "Any click" event handler, then unhandled_event will never be called. Here we haven't added an "Any click" handler though, so we could invoke unhandled_event by interacting with the character another way. "Interact" is handled, but "Look at" is not (in this example, since we didn't define a "Look at" event). The parameters to unhandled_event are a bit wonky and inconsistent, so it's always important to check the manual entry to make sure you have the right ones. For "Look at character" the What parameter is 3 and the Type parameter is 0:

Code (ags) Select
function unhandled_event(int what, int type)
{
  if (what == 3)
  {
    if (type == 0)
    {
      player.Say("I don't see anything special about that!");
    }
  }
}


This would be called if you used the "Look at" cursor on the character. If you ever defined a "Look at" event for the character, then unhandled_event would no longer be called of course.