Page 1 of 1

Triggering Animations In Python Script?

PostPosted: Mon Nov 03, 2008 6:12 am
by Robert The Rebuilder
I need to trigger an animation based on conditions that only a script can detect, as an alternative to triggering animations strictly through AlcScript.

I've been looking at the Kadish pillar animations and the associated Python script to see how it's done, and I've made the following observations:
  • The plATCAnim names have the form prefix_middle_anim_N where prefix is the channel name contained in plAGModifier; middle is the name passed in as a Python parameter; and N is some indicator of the animation's order in a series (or just 0 if it is a single animation).
  • The animation-related Python parameters provided to the plPythonFileMod are an AnimationName (i.e. the middle part of the animation name) followed by an Animation (that has a reference to the plAGMasterMod) - and they share the same ID/index.
  • The Python script has just one attribute for this collection of python parameters - a ptAttribAnimation instance. Somehow, the animation name and subsequent animations are all folded into this one attribute.
  • The use of the optional byObject flag seems to be when the script wants to activate each animation in the group individually. If it is specified, then all uses of the ptAttribAnimation in the script must use the byObject map to access the individual animation.
  • When not using the byObject flag, the 'value' and 'animation' members of the ptAttribAnimation seem to be interchangeable.

I tried enabling the use of animation arguments in the 1.5.X plug-in code base, where if plPythonParameter._ExportScript() detects an 'animationlist' type argument in the AlcScript argument list for the python file mod, it recurses on the references, creating a plPythonParameter with the same ID/index. For example, the AlcScript for the animationlist looks like this:

Code: Select all
              - type: animationlist
               refs:
                 - type: animationname
                  value: DoorOpen
                 - type: animation
                  ref: 006D:s111Door0


Note that the reference is to the plAGMasterMod (0x006D).

To test this, I made sure my animations followed the naming convention I've seen above. After exporting and examining the PRP file, it appears that the Python arguments were created correctly. When running in URU, the Python script does obtain a seemingly valid ptAttribAnimation. I can print out the return value of the getdef() method and animation.getFirstKey().getName(), which appear to be in order. But when I call the animation.play() method, nothing happens. I encased the call in a try-except block, but no exceptions are thrown. And no animation. :(

[And yes - I delete the .SAV file each time before firing up URU.]

Has anyone tried triggering animations from within Python scripts? Have you had any success?

Re: Triggering Animations In Python Script?

PostPosted: Mon Nov 03, 2008 9:43 am
by D'Lanor
Hook up your animation(s) to a responder and use PtAttribResponder. That is so much easier.

Re: Triggering Animations In Python Script?

PostPosted: Tue Nov 04, 2008 11:20 am
by Robert The Rebuilder
You're right: for basic triggers of animations, even going forwards and backwards, that is the way to go.

But for the moving columns in Shell 111, there's a problem. Similar to the Kadish pillars, I want to play only a portion of the animation, depending on the settings of the buttons when the levers are pulled. Ideally, I would be able to pass the full animation for each column to the Python script, which can calculate how much of the animation to play (and whether it is forwards or backwards).

If I use responders to do this, I would first need to enable the setting of the speed, begin and end values for ptAnimCmdMsg via AlcScript (currently it doesn't support this). But the larger problem would be to create a state for each possible start/end time combination for the animation. Given 4 possible positions of a column, that would be 12 different animation states per column - repeated for each column in a separate responder. The script would then choose which state to use, depending on the button settings. It can be done, but boy - what a lot of AlcScript that would be!

Given that there's currently no alternative (unless PyPRP 2.0 comes out), maybe I'll have to do it that way.

Re: Triggering Animations In Python Script?

PostPosted: Tue Nov 04, 2008 2:39 pm
by J'Kla
This points to where we need some help from Cyan either in the form of tools or at least instructions.

I don't think either are likely to be forthcoming.

Re: Triggering Animations In Python Script?

PostPosted: Tue Nov 04, 2008 4:07 pm
by D'Lanor
But you can play a portion of an animation. Based on the set framerate of 30 fps you can calculate the start and end times. It is one of the first things mentioned in the animations wiki, but nobody ever seems to use it that way.

Re: Triggering Animations In Python Script?

PostPosted: Wed Nov 05, 2008 2:24 pm
by Jojon
Err, isn't it just a matter of setting up one named animation definition for each distance each column travels and call the relevant four?