i wish to get the frame number I am on for an action in my rig.
I have ActionActuator on, and a float property “Number” attached to the “frame property” option in the actuator.
i also have a property sensor that is set so that whenever “Number” == a value, it does some other stuff…
but this is no working. i have Debug enabled in game for Number, and it is working. The value of the property is increasing until the animation ends. but, the property sensor never triggers, and using print statements in a python file, it seems the property is always 0, yet the debug shows otherwise in run-time?
Can somebody please help me?
Also, how would I use the python ActionActuator.frame method to do a similar result myself?
Thanks so mcuh, it is much help!
Edit, my logic:
PlayerRig: WeaponObj: PlayerRig:
PropertySensor —>PythonCont—>ActionAcuator
(set as equals)
Python code:
sens = cont.sensors[‘PropSens’]
PropSens.value = 74 (with my game logic property set to int)
if PropSens.positive:
print(“Victory!”)
Then I also have a debug loop…
for i in range(0, 150):
print(PlayerRig[‘PropSense’]
I have tried multiple debugs… as said before, they always return that the value is 0. Same for if I try using.frame method. Please somebody tell me what I must be do wrong.
You have (float) property, and animation counts as float. You probably see frames like 23.9800 and next frame is example 24.012.
Now we test if 24 equals 24.012 -> Nope.
Set your property to integrer and it should work. But is very dangerous trigger important happenings with this beqouse, if game lag just that moment and that frame skipped. Less important actions may triggered with that way of course (Like walk sound in certain frame)
In python we can use it same way.
I have done essentially the same as BPR in the past, but formatted a little differently.
The problem is, I think, is when you have the action and property sensors not controlled on the object. At least when I tried something similar to what you were doing, that is what I deduced to be an issue.
Here is a .blend that does what it sounds like you want: framecount.blend (509 KB)
It’s probably not the most elegant way of handling this, but it works.
In python we can read animation frames directly without any properties.
Next example is ripped from our game and do nothing at lone.
I wish if it helps to show, how that work. This time python code is module not a scipt.
As mentioned earlier, frames are floats. Checking with equal does not really work as you would not match the exact precission of a float number.
What you can do is to make the measuring property an integer. Then you can check with equal on this one with a whole number. Be aware this check might have several solutions e.g 2.1666 == int 2 and 2.73333 == int 2
Nevertheless is the design of you logic really a good one?
I think you want to play an animation. When the animation ends you want to do a decision what comes next.
So all you need is to determine when the animation ends. You do not need to look for the frame number. The action actuator already knows the end. You can check that with the ActuatorSensor.