Feature suggestion (Discuss)

Started by After, Fri 07/11/2003 07:52:23

Previous topic - Next topic

After

A new event for on_event(int event,int data),
event=CHAR_STOP, data=CHARID.

It seems that scripters are routinely having to put
Code: ags
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).

Gilbert

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.

After

Just so. I should really put something like the actual code required in case of confusion -
Code: ags
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 -
Code: ags
int watchEGO;
function on_event(e,d){
  if(e==CHAR_STOP){
    if((d==EGO)&&(watchEGO)){
      stuff();
}}}

Gilbert

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().

Pumaman

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.

After

#5
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 -
Code: ags
function on_event(e,d){
if(e==CHAR_STOP){
if(d==EGO){
stuff();
}}}
Or if applying the same code to different characters -
Code: ags
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.

SMF spam blocked by CleanTalk