Well, the interpreter said it best: “name appliedImpulse not defined”
However, even if it was, the variable “Smack” would only receive what the function appliedImpulse returned (if it returned anything). For example:
def getSum(x=0, y=0)
return x + y
Smack = getSum() # Smack is 0, because 0+0=0
Smack = getSum(1, 2) # Smack is 3, because 1+2=3
Smack = getSum # Now "Smack" is a shorthand for the function getSum()
# And now you could use it in place of getSum():
print Smack(5+5) # prints 10
# !!!!! NOTE !!!!!!!
# "Smack = getSum" does not "replace" every instance of "Smack" with "getSum"
# Python does not "cut and paste" like that.
# Instead "Smack" becomes a *reference* to "getSum"
Anyway, going back to why the interpreter complained; the function “applyImpulse()” does not exist in your global scope; It’s a method of the owner, or in your case, the “Kay” object.
So, the working version of your code would look like this:
cont = GameLogic.getCurrentController() # GameLogic is imported automatically
Kay = cont.getOwner()
WhereKayisAt = Kay.getPosition()
Smack = Kay.applyImpulse # "Smack" is now a reference to "Kay.applyImpulse"
daforce = [0, 10, 0.3]
Smack(WhereKayisAt, daforce)
A cleaner, more “general purpose” version could look (and be used) like this:
cont = GameLogic.getCurrentController()
Kay = cont.getOwner()
Social = GameLogic.getCurrentScene().getObjectList()["OBSocial"]
Jimmy = GameLogic.getCurrentScene().getObjectList()["OBJimmy"]
def Smack(dyn_GameObject, daforce):
dyn_GameObject.applyImpulse(dyn_GameObject.getPosition(), daforce)
daforce = [0, 10, 0.3]
Smack(Kay, daforce)
Smack(Social, [0, 0, 0]) # Let's face it....no one would dare.
daforce = [100, 100, 100]
Smack(Jimmy, daforce) # He's been a very bad boy.
Lol, well, if there’s still something not working, or just something you don’t understand, feel free to ask.