Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Tamanegi on Mon 08/10/2012 17:01:03

Title: Object part of idle animation
Post by: Tamanegi on Mon 08/10/2012 17:01:03
I have a character in one room with an idle animation (takes a cup, sips and puts it pack). The cup is an object, but while the cup is in her hand, it is part of the animation and the object is made invisible.

For this, in room_RepExec() I have:
Code (AGS) Select
  if (cReceptionist.View==REC_IDLE)
  {
    if (cReceptionist.Frame!=4) oCup.Visible=false; else oCup.Visible=true;
  }

The frame check is for continuity reasons so the object doesn't flicker before it is visible again.
It works, but if I have blocking movement etc. while the idle animation is starting or ending, the object visibility is not updated until the blocking action has ended.

Any ideas about how to solve this? The cup needs to be clickable by itself while not in her hand.
Title: Re: Object part of idle animation
Post by: Crimson Wizard on Mon 08/10/2012 17:54:08
I may not know some tricks, but if I had to solve this, I won't be using idle animation at all. Instead I'd set up a timer and do everything triggered by it:
- hide object;
- either start blocking animation, or start non-blocking animation and wait until it ends (use Wait command, or check for Character.Animating in "repeatedly execute");
- show object.
Title: Re: Object part of idle animation
Post by: OG on Mon 08/10/2012 18:38:21
How about not blocking? I might be missing the point here.


In the rooms' room_Load put in something like this:

Code (AGS) Select

if (player.HasInventory(icup){
//Whatever
}
else{ cReceptionist.Animate(?, ?, erepeat, eNoBlock);
}


Put this in repeatedly_execute:

Code (AGS) Select
if (cReceptionist.View==REC_IDLE && cReceptionist.Frame!=4)
  oCup.Visible=false;
else{ oCup.Visible=true;


And rework it to suit.
Title: Re: Object part of idle animation
Post by: Tamanegi on Mon 08/10/2012 19:37:48
Okay, I feel dumb... It's so easy I should have thought of it myself. It works, but now there is another problem: The interaction functions for the character have to be in the global script so I can't have the animation stop and make the cup object visible again before starting any conversations. If I don't, the character will either still be locked in the animation view, or if I don't lock it, she will change to the speech view and the cup will disappear because it is not set to visible yet.

@Onker:
The animation is eNoBlock. The problem was appearing when the player did something blocking, which includes speaking to the character.
Title: Re: Object part of idle animation
Post by: Crimson Wizard on Mon 08/10/2012 20:07:42
Quote from: Tamanegi on Mon 08/10/2012 19:37:48
Okay, I feel dumb... It's so easy I should have thought of it myself. It works, but now there is another problem: The interaction functions for the character have to be in the global script so I can't have the animation stop and make the cup object visible again before starting any conversations. If I don't, the character will either still be locked in the animation view, or if I don't lock it, she will change to the speech view and the cup will disappear because it is not set to visible yet.
It is one of those situations you may have to refer to an object by number rather than by name (which is unknown for Global Script).
I.e. instead of oCup use object[N], where N is oCup's index in the room.

Eurgh, I hate this to be honest, and I'd wish the object names were accessable via room name (Room1.oCup), but unfortunately AGS does not support this.

If the non-player character may be in different rooms, check current room first ( if (player.CurrentRoom == XXX) ), otherwise this may cause bugs. If NPCs is always in the same room with oCup, then this check is not mandatory.
Title: Re: Object part of idle animation
Post by: Tamanegi on Mon 08/10/2012 20:13:02
Thank you for clarifying this - I actually tried Room[3].oCup and its iterations - and for telling me how to access the object from outside the room script. Had that not been possible, it would drive me mad trying to manipulate objects through NPC interaction.

It's working now :)
Title: Re: Object part of idle animation
Post by: Khris on Mon 08/10/2012 22:16:40
You can put a repeatedly_execute_always() in the room script.
Just add it, it is called automatically.
Title: Re: Object part of idle animation
Post by: Tamanegi on Tue 09/10/2012 17:41:34
Thank you, that is... very good to know. And makes me wonder why it isn't listed in the room events; it would have saved me a few hours of code puzzling.
Title: Re: Object part of idle animation
Post by: Andail on Tue 09/10/2012 19:10:30
Quote from: Tamanegi on Tue 09/10/2012 17:41:34
Thank you, that is... very good to know. And makes me wonder why it isn't listed in the room events; it would have saved me a few hours of code puzzling.

Why what isn't listed? Repeatedly_execute is listed in the events pane. In fact, it's the only way to use it.
Title: Re: Object part of idle animation
Post by: Crimson Wizard on Tue 09/10/2012 20:07:23
Quote from: Andail on Tue 09/10/2012 19:10:30
Quote from: Tamanegi on Tue 09/10/2012 17:41:34
Thank you, that is... very good to know. And makes me wonder why it isn't listed in the room events; it would have saved me a few hours of code puzzling.

Why what isn't listed? Repeatedly_execute is listed in the events pane. In fact, it's the only way to use it.
He meant repeatedly_execute_always, not just Repeatedly_execute.

Quote from: Tamanegi on Tue 09/10/2012 17:41:34
Thank you, that is... very good to know. And makes me wonder why it isn't listed in the room events; it would have saved me a few hours of code puzzling.
There's the list of functions that may be put into any script:
http://www.adventuregamestudio.co.uk/wiki/?title=Multiple_Scripts