Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: After on Fri 07/11/2003 07:52:23

Title: Feature suggestion (Discuss)
Post by: After on Fri 07/11/2003 07:52:23
A new event for on_event(int event,int data),
event=CHAR_STOP, data=CHARID.

It seems that scripters are routinely having to put
if(character[EGO].walking==0){ ...stuff... };
in repeatedly_execute(), which may well be more clutter than they really want in their main loop (bearing in mind that it's all unoptimized bytecode).

Also, I imagine that the engine already knows about this event, and needs only to share the information.

Note: The event of ceasing to walk is not the same as the state of not-walking, but I think this is generally what scripters are trying to emulate. At least that's what I've been thinking about lately (and trying decide how far to go with it).
Title: Re:Feature suggestion (Discuss)
Post by: Gilbert on Fri 07/11/2003 08:01:29
Sounds reasonable, but only if the engine is really doing "The event of ceasing to walk is not the same as the state of not-walking" like you mentioned, otherwise after the character stopped, the event interaction would be executed every game loops, which is not very pleasant (so even in the current if(character... approach you need to add something to prevent it to run more than once).

Maybe if it can be made like the IsTimerExpired() function which would report TRUE only once after the timer had reached 0.
Title: Re:Feature suggestion (Discuss)
Post by: After on Fri 07/11/2003 08:49:16
Just so. I should really put something like the actual code required in case of confusion -int watchEGO;
function repeatedly_execute(){
 if(watchEGO){
   if(character[EGO].walking==0){
     watchEGO=0;
     stuff();
}}}
Of course, in practise we would still have a flag to signify our interest in the event, so the amount of text is about the same -int watchEGO;
function on_event(e,d){
 if(e==CHAR_STOP){
   if((d==EGO)&&(watchEGO)){
     stuff();
}}}
Title: Re:Feature suggestion (Discuss)
Post by: Gilbert on Fri 07/11/2003 09:08:49
I think in this case teh on_event thingie should be:
int watchEGO;
function on_event(e,d){
if(e==CHAR_STOP){
if((d==EGO)&&(watchEGO)){
watchEGO=0;
stuff();
}}}

So it wouldn't help much, just a bit tidying up of the codes, unless of course, it can be made that on_event(CHAR_STOP,EGO) would only execute once when he stoped, automatically like IsTimerExpired().
Title: Re:Feature suggestion (Discuss)
Post by: Pumaman on Fri 07/11/2003 16:36:23
Good idea, this would be a cleaner and faster way.

However, the issue is that if a blocking script was running when the character stopped, on_event wouldn't be able to run and therefore the event could get missed. This could be worked around by queueing up the events of course, so I'll add it to my list.
Title: Re:Feature suggestion (Discuss)
Post by: After on Sat 08/11/2003 02:28:26
Gilbot: Yes, the call is made once only each time a walking character stops.
I omitted that line because it is no longer required for the basic mechanism, only to (optionally) indicate whether we are interested in the event, which depends on the game design. If we wanted to signal disinterest, it would probably make more sense to do so in "stuff()".

If we always used it, we would simply put -
function on_event(e,d){
if(e==CHAR_STOP){
if(d==EGO){
stuff();
}}}
Or if applying the same code to different characters -
function on_event(e,d){
if(e==CHAR_STOP){
stuff(d);
}}


Quote from: Pumaman on Fri 07/11/2003 16:36:23[...]However, the issue is that if a blocking script was running when the character stopped, on_event wouldn't be able to run and therefore the event could get missed.[...]
Hmm. I hadn't considered blocking scripts losing events. I'll have to be careful about that.