Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: bx83 on Fri 16/03/2018 01:58:20

Title: Trouble with blocking animation playing instantly
Post by: bx83 on Fri 16/03/2018 01:58:20
I wrote a function for picking up an object a while ago, which worked fine. I've recently added another animation, and now it doesn't.
HOWEVER, if I turn off or delete code for the animation I've added, it still does it.

Here's my code:

function hStick_Interact()
{
cJulius.FaceObject(oStick);
cJulius.SayBubble("&244 It's my friend - mr sticky-stick.");
cJulius.PickUp(eLow, iStick, oStick);
hStick.Enabled=false;
}


in GlobalScript.asc:

function PickUp (this Character*, PickUpHeight height, InventoryItem *i, Object *o, bool visibility)
{
    int loop=0;
    int _height=0;

    if (height == eLow) {
        _height=50;     //low animation
    }
    if (height == eHigh) {
        _height=49; //high animation
    }

    if (this.x <= o.X) {
        loop=2; //right
    } else {
        loop=1; //left
    }

    this.LockView(_height);
    this.Animate(loop, 0, eOnce, eBlock);
    this.AddInventory(i, 0);
    o.Visible = visibility;
    this.UnlockView();
}


Firstly, I have tried this with and without UnlockView().

For the code:
-first, julius walks to a predefined position for hStick, a hotspot.
-then he faces the stick
-he say's something ("It's my friend - mr sticky-stick.")
    -it goes into the function pickup - this is a low pickup, to the right, so:
        LockView(50);
        Animate(2, 0, eOnce, eBlock);
    -the animation is supposed to happen - IT DOESN'T
    -inventory item is added, object is set to invisible
    -view is Unlocked (or not, when I comment it out, makes no difference anyway)
-the HotSpot for this object, hStick, is switched off

Here's a video:

video (http://redrom.ltd/img/stick%20animation%20problem.webm)

yes, I have tried plotting out the course of the code with breakpoints, this appears to be the only way.

Why, oh god why, is it not animating?
Title: Re: Trouble with blocking animation playing instantly
Post by: bx83 on Fri 16/03/2018 02:01:15
function wirtten here: http://www.adventuregamestudio.co.uk/forums/index.php?topic=54907.msg636563067#msg636563067 (http://www.adventuregamestudio.co.uk/forums/index.php?topic=54907.msg636563067#msg636563067)
Title: Re: Trouble with blocking animation playing instantly
Post by: bx83 on Fri 16/03/2018 02:06:07
Also, the extra animation I've added:


function room_Load()
{
...
    if (JuliusDied) {
        cJulius.LockView(81);
    }
}

function room_AfterFadeIn()
{
...
    if (JuliusDied) {
        cJulius.Animate(0, 0, eOnce, eBlock); //lying down/getting up animation
        cJulius.SayBubble("&1353 Hmm, what a strange dream...");
        JuliusDied=false;
        cJulius.UnlockView();

        cJulius.ChangeView(1); //julius
        cJulius.SpeechView=2; //julius speech
        cJulius.AnimationSpeed=-7; //normal animation speed
        cJulius.SetWalkSpeed(4, 4); //normal walk speed
    }
}


JuliusDied is currently set to false; but this code is the only other place in the room I have 'LockView' or 'Animate'.
Title: Re: Trouble with blocking animation playing instantly
Post by: Gilbert on Fri 16/03/2018 05:40:02
Are 49 and 50 the correct View numbers for the animations? If they do not contain any frames it may make the animation appear to end immediately.

I ask this because this line:
Code (ags) Select
this.LockView(_height);
IMO unless there are some justified reasons, it is VERY confusing to use a variable named HEIGHT to hold a view number, so this looks like some typo by referring to an incorrect variable to people reading the code.
Title: Re: Trouble with blocking animation playing instantly
Post by: Khris on Fri 16/03/2018 08:26:26
The .Animate() command has a delay of 0, so my guess is your frames for the view that's working have a delay set in the view editor, while the new pickup view's frame delays are all still 0.
Title: Re: Trouble with blocking animation playing instantly
Post by: bx83 on Fri 16/03/2018 12:43:49
Yes 49 and 50 are the view numbers.

No, changing from 0 to 1 does nothing; I changed it to 10, still nothing. Not even 300ms longer of nothing; just nothing. Animation won't play.
Title: Re: Trouble with blocking animation playing instantly
Post by: bx83 on Fri 16/03/2018 12:52:42
Aha!

If I add in a display to the code:


...
    } else {
        loop=1; //left
    }

    Display("view %d, loop %d", _height, loop);
    this.LockView(_height);
    this.Animate(loop, 0, eOnce, eBlock);
    this.AddInventory(i, 0);
    o.Visible = visibility;
...


It works! But If I comment it out, it doesn't work, same problem as before.
It must require user interaction to work properly, or a delay of some kind?
Title: Re: Trouble with blocking animation playing instantly
Post by: bx83 on Fri 16/03/2018 12:57:18
Further:
It's something to do with this room specifically; it only happens here. I walked into the other room, and it played animation normally.
Therefore, something in room load is the problem.
I can post my entire code for this room to this thread, but... would anyone read it? :P
Title: Re: Trouble with blocking animation playing instantly
Post by: bx83 on Fri 16/03/2018 13:05:38
Further further:

The animation seems to *only* play in this room; in yet other rooms, it doesn't play.
I noticed he says something before each pickup with SayBubble (from the speechbubble module (http://www.adventuregamestudio.co.uk/forums/index.php?topic=55542.0)), but not this one specifically.
I'm now trying to think if anything's changed with speechbubble... and can't. I haven't touched it in 2 months. But Snarky, who wrote it, might make a sudden eureka moment? :P
Title: Re: Trouble with blocking animation playing instantly
Post by: bx83 on Fri 16/03/2018 13:12:14
Further further further:
It has something to do with sound.
When I write a speech number, ie.
cJulius.SayBubble("&123 a spoken line");
it will not do the animation.

When I do not write a speech number:
cJulius.SayBubble("a silent line");
It plays the animation.

So...... god knows. But there we are, a bit closer to a solution.

Let me reiterate, I haven't done anything to SpeechBubble v0.8 or TotalLipsync v0.6 at all in the last few months.
Title: Re: Trouble with blocking animation playing instantly
Post by: bx83 on Fri 16/03/2018 13:29:43
Well, it solved.
Just add this line:

Wait(1);

Great! Several hours of pain caus I was missing out a screen update :P

No idea why... SpeechBubble? The only thing calling TotalLipsync when pronouncing speech sound (as in, spoken &123 lines).
I'll let Snarky figure it out :P
Title: Re: Trouble with blocking animation playing instantly
Post by: Khris on Fri 16/03/2018 13:47:12
One thing I suspected was that maybe the FaceObject is interfering since it's non-blocking? But the SayBubble is inbetween.
Anyway, making the FaceObject blocking is worth a try I guess.
Title: Re: Trouble with blocking animation playing instantly
Post by: bx83 on Fri 16/03/2018 22:14:17
Possibly, but it was happening in rooms where FaceObject was not even used. I'd like to try this solution, but I'll just have to wait until this randomly and inexplicably happens again :P