Adding global event handlers

Started by Llelan D., Sat 30/05/2009 01:52:02

Previous topic - Next topic

Llelan D.

In the help file under "Predefined global script functions", it says
QuoteIn your main global script file, there are some functions which are automatically added when you create the game. These are global events, and the function is called when a particular event happens. There are also some other events which you can add if you want to.
However, nowhere does it specify HOW to add these events.

The few events that are included in a templated new project are surrounded by these tags.
Code: ags
#sectionstart unhandled_event  // DO NOT EDIT OR REMOVE THIS LINE
    ...
#sectionend unhandled_event  // DO NOT EDIT OR REMOVE THIS LINE


This strongly implies that global events are like other events, they must be added or removed by the AGS editor GUI and not copied, pasted, or written manually since this could confuse the automatic synchronization between the code source and the GUI management.

I can find no GUI method to add, manage, or remove global events, nor any documentation describing this, or even if it is or is not required.

I believe, from the text I've read so far written by people discussing global event code, that there is no GUI method for adding global events and that the sectionstart and sectionend tags around these event handlers are not needed.

Can anyone let me know how global event code is intended to be added and removed in the AGS editor?

Ghost

#1
QuoteThis strongly implies that global events are like other events, they must be added or removed by the AGS editor GUI and not copied, pasted, or written manually since this could confuse the automatic synchronization between the code source and the GUI management.
Sounds perfectly sensible, but it's not the case- all additional functions are added manually, there's no IDE element for that.

Open the help file (F1  ;) ) and find  "Predefined global script functions" (a shortcut is to do a search for "unhandled events").

There you will find a list of all global events that are part of AGS, but not included in the game templates (because many of them aren't necessary for a standard game). There's several of them, all well described, so you'll easily see if you need them or not.

To add one of them, just type the proper code. For example, if you want unhandled events, just type

Code: ags

function unhandled_event (int what, int type)  {
    if (what == 1 && type == 1) { whatever you want to happen };
    .
    .
    .
}


AGS will automatically execute the code for you, all you need is to enter the proper functions. Keep in mind that these are merely "entry points"- what you DO in any section of, say, unhandled_event is up to you. A sensible thing would be to write an additional function say_random that causes the player character to say one of ten random "I can't use that" lines, and call that from the unhandled_event. In the same way you can check all sorts of conditions with "on_event", and so on. It's a superb way to make your game more elaborate and flexible.


You also don't need to bother with the #sectionstart/#sectionend lines; as I recently learned they are "leftovers" from previous versions, so no need to add them to your new functions.

Llelan D.

Quote from: Ghost on Sat 30/05/2009 02:37:44Sounds perfectly sensible, but it's not the case- all additional functions are added manually, there's no IDE element for that.
That's what I thought. Although, 30 seconds to write a paragraph describing that would've saved me many hours of head-banging frustration searching for an answer before I finally gave up and posted.

It would seem that the documentation, and especially the demo game, are merely patched from 2.72 and have never been properly re-written. A perfect example is global messages. The manual still mentions them as if they still exist in the "Setting up the game" section, and they are still used in the demo game even though the current AGS editor can not display or edit them. The actual situation is only mentioned in the "Upgrading to AGS 3.0" section: the last place someone trying to learn the editor is going to look.

Like I said, many wasted hours of head-banging frustration.

Thank you very much for your help.

JpSoft

I had the same trouble a lot of times. You found a lot of info not updated very often, and sometimes you are using functions that are not supported now. I guess this is because CJ have enough work improving AGS continuosly, and update the manual (even the knoweldge base) is not a prioritary thing to do, specially since what you are updating could be obsolete in the next AGS version. Actually, i remember a very nice tutorial created in spanish just some months ago, which is very out-of-date actually.

Meanwhile AGS keeps its current wonderfull improvement level, its very difficult to keep the manual or any tutorial fully updated. Maybe CJ will add a "Make a Dontacion" button in the download page, and with the money we all will donate, he could pay to someone to do this  ;D

... and maybe, in the years to come, AGS will be available in different languages... (maybe when England win another Football World Cup  :=)

Jp

Khris

Afaik CJ does a pretty thorough job updating the manual every time a new version is released. There a few, very minor parts still in there that need updating, but the rest gets continuously improved and rewritten to reflect all the recent changes.

People who aren't used to object oriented programming or programming in general might sometimes have a hard time understanding the examples or explanations, but still, blaming the manual is just a cheap cop-out IMO.

Having said that: player.ActiveInventory!! :=

RickJ

#5
It's often more difficult to identify outdated material in the manual than it is to correct it.  It would probably be a good idea to create a post in the Tech forum describing the outdated or erroneous portions of the manual.   Such issues are usually quickly resolved.        

I would also recommend checking out the DemoQuest documentation in the "Games in Production" forum.

http://www.adventuregamestudio.co.uk/yabb/index.php?topic=34048.msg443220#msg443220

There are Global Script, Room Script, and Script Header templates  you may find helpful.

SMF spam blocked by CleanTalk