Page MenuHome

BGE: Added getActionName() function to KX_GameObject()
ClosedPublic

Authored by Mateo de Mayo (mateosss) on Aug 2 2015, 8:55 AM.

Details

Summary

It works similar to getActionFrame(), you have to give a layer or not (for layer 0) as the argument and it returns the name of the animation that the object is currently playing.

Example:

import bge
own = bge.logic.getCurrentController().owner
own.playAction("SomeAction",0,20)
print(own.getActionName())

SomeAction

Here is an example file, just open the blend file with the terminal opened
and press P, you can see how the current animation is being printed:

Diff Detail

Event Timeline

Mateo de Mayo (mateosss) retitled this revision from to BGE: Added getActionName() function to KX_GameObject().
Mateo de Mayo (mateosss) updated this object.
Mateo de Mayo (mateosss) set the repository for this revision to rB Blender.
Porteries Tristan (panzergame) requested changes to this revision.Aug 2 2015, 7:04 PM
Porteries Tristan (panzergame) edited edge metadata.
Porteries Tristan (panzergame) added inline comments.
source/gameengine/Ketsji/BL_Action.h
49

BL_Action contains the blender action, so GetName function should return m_action->id.name and variable m-name will be removed.

source/gameengine/Ketsji/KX_GameObject.cpp
3960

space between operator

This revision now requires changes to proceed.Aug 2 2015, 7:04 PM
Thomas Szepe (hg1) requested changes to this revision.Aug 2 2015, 8:05 PM

Please provide an example file which is showing the use case for this patch.

Rst documentation change for getActionName() is missing.

source/gameengine/Ketsji/BL_Action.h
49

Seems to be the indentation wrong. We use one tab.
Also the asterisk position is wrong. We use put it in front of the variable or method name.
const char *m_name;
const char *BL_Action::GetName()
This must be changed for every new or edited line in the patch.
I only do a comment it here, I don't make a comment to every wrong place in your patch.

Mateo de Mayo (mateosss) updated this revision to Diff 4799.EditedAug 3 2015, 12:04 AM
Mateo de Mayo (mateosss) updated this object.
Mateo de Mayo (mateosss) edited edge metadata.
Mateo de Mayo (mateosss) removed rB Blender as the repository for this revision.
  • Added space between operators and in all similar functions too.
  • Removed m_name variable and using m_action->id.name. id.name returns "AC"+"Name of Animation"), so I do a workaround in KX_GameObject.cpp, I don't know C++ and I don't know if it is the better way to do it.
  • Added an if-else statement, to check if m_action is null, this prevents from crash when you use playAction() with a wrong animation name, and then the getActionName()
  • Added example file in the summary
  • Corrected syntax from "char* variable/method" to "char *variable/method"
  • Corrected tabs
  • Added paragraph to docs
source/gameengine/Ketsji/BL_Action.cpp
307

To fix the "AC" prefix you can just return : m_action->id.name + 2
2 for two letters after.

Mateo de Mayo (mateosss) edited edge metadata.
Mateo de Mayo (mateosss) marked 3 inline comments as done.

Improved the removing of "AC" from action name.

Porteries Tristan (panzergame) edited edge metadata.
Porteries Tristan (panzergame) added inline comments.
source/gameengine/Ketsji/BL_Action.cpp
307

you forgot space for the +

Mateo de Mayo (mateosss) edited edge metadata.
Mateo de Mayo (mateosss) marked an inline comment as done.

Corrected spaces.

Campbell Barton (campbellbarton) requested changes to this revision.Aug 3 2015, 12:24 PM
Campbell Barton (campbellbarton) added inline comments.
source/gameengine/Ketsji/KX_GameObject.cpp
3967

Theres no need to go via STR_String, just PyUnicode_FromString is fine.

This revision now requires changes to proceed.Aug 3 2015, 12:24 PM
Mateo de Mayo (mateosss) marked an inline comment as done.Aug 3 2015, 2:01 PM

Changed conversion function to PyUnicode_FromString

@Mateo de Mayo (mateosss) : could you connet you in irc #bgecoders to give your email to make the futur commit

Mateo de Mayo (mateosss) edited edge metadata.

Re-corrected conversion to String

I still can't see any use case for this patch. Also your file don't show me for what getActionName() can be used.
The only use that I can see is, that you can use it in an other script to check if actually an action with a certain name is playing.

Also the same can be done by using a property to store the actual playing action. So you're patch only saves us one line of python code per action.

import bge
own = bge.logic.getCurrentController().owner
own["ActionName"] = ""

if own["Action"] = 1: 
    own.playAction("SomeAction",0,20)
    own["ActionName"] = "SomeAction"

if own["Action"] = 2: 
    own.playAction("SomeOtherAction",0,20)
    own["ActionName"] = "SomeOtherAction"

print(own["ActionName"])

@Thomas Szepe (hg1) : Of course the user can rewrite a lot of systems externaly. But what we risk to add a little stuff which simplify the work of the user ?

In many games you may have to make systems of cutscenes. As you say now you have to make your own system for storing the current action, to know what is the next. As the blender variable is there and we only have to implement a method that can be used or not. It is good to have some methods that allows us, to return quickly some things like the current frame, name of animations, etc.

PD: @Porteries Tristan (panzergame) can you indicate me how to proceed with the IRC?

This revision was automatically updated to reflect the committed changes.

Why was this committed?