animation not animating in rep exec always SOLVED

Started by smartastreacle, Fri 15/10/2021 12:45:55

Previous topic - Next topic

smartastreacle

Oookay - raising my head with a question again (always find this scary)  8-0
Imagine an industrial complex overrun by aliens. We enter the room (industrial complex), an alien scout spots us, dives back into a shed where it raises the alarm and the alarm brings out a small army of aliens who line up and start shooting at us. That's what I want. Every thing works fine until the shooting bit - that animation stops on the first frame. I put that animation in repexec-always because I thought with enoblocking it would work there whilst with enoblock in standard repexec it did not work. However, it stops on the first frame  (wtf)  Why? Similar situations have been covered elsewhere but I still just do not get it.
Here's the code - when it starts the scout is already animating. What do you think? I know this is going to be something simple again. I shall steel myself.  :-D

Code: ags

function room_RepExec()
{
  ShakeScreenBackground(5, 2, 80); 
}

function repeatedly_execute_always()
{
  if (object[0].Frame == 39){    // alien scout already animating from room after fade in
    object[3].Animate(0, 5, eRepeat, eNoBlock);   ///    siren
    asiren.Play(eAudioPriorityNormal, eRepeat); 
    object[4].Animate(0,  15,  eOnce, eNoBlock);   // army
    }
    if (object[4].Frame == 13){
      object[5].Visible = true;      
      object[5].Animate(0, 10, eOnce, eNoBlock);    // army lining up to fire
      if (object[5].Animating){
        Display("attacking!");       // I know it's animating because this shows
    }
    }
}


Cassiebsg

Uhm?

QuoteDisplay("attacking!");       // I know it's animating because this shows

How on earth are you doing a blocking action (Display) inside rep_exec_always?  ???

But to answer your question, you need to understand that rep_exec_always runs 40 time a second! (40 is AGS default, might be more or less if you have change it - but most people leave it in the default).

So, every time the code runs, it reads the code and starts doing it again, and again and again. (40 times in a second) This is the reason that you can't see it animating more than the 1st frame.
What you need to do, is create a start condition (to set things in motion), and then check for if the object is not animating if (!object
  • .Animating) // the run the animation code.[/b]
    This away, it will only run the animation code, if it has stopped animating (and thus you can see the object animating).
There are those who believe that life here began out there...

smartastreacle

#2
'How on earth are you doing a blocking action (Display) inside rep_exec_always?  ???'  (laugh) No idea, but it happened!

Apart from that, your bold emphasis really hammered it into my head.

I was checking for object 4 not animating, ie, checking it had finished instead of checking for object 5 not animating (at least that was one of the many things I tried). That was the answer. And now it works and I can enjoy the weekend. Brilliant. You are a super star. Thank you.   (nod)

For completeness, this is what I ended up with. Beware the world! They are coming!

Code: ags


function room_RepExec()
{
  ShakeScreenBackground(5, 2, 80); 
}

function repeatedly_execute_always()
{
  if (object[0].Frame == 39){    // alien scout already animating from room after fade in
    object[3].Animate(0, 5, eRepeat, eNoBlock);   ///    siren
    asiren.Play(eAudioPriorityNormal, eRepeat); 
    object[4].Animate(0,  15,  eOnce, eNoBlock);   // army
    }
    if (object[4].Frame == 20){
      object[5].Visible = true;     /// army firing

    if (!object[5].Animating){
      object[5].Animate(0, 10, eRepeat, eNoBlock);
    }
    }
}



SMF spam blocked by CleanTalk