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?
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)
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'.
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:
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.
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.
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.
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?
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
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
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.
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
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.
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