Storing linear velocity data from bge in file

I am simply trying to get the linear velocity of a moving block in blender game engine and store it in a .py file. I am a beginner, however, and am having trouble doing this. Could someone please take a look at my script?

import PhysicsConstraints
import GameLogic

controller = GameLogic.getCurrentController()
senList = controller.sensors
actList = controller.actuators

r = senList["rightsensor"]
mr = actList["moveright"]
a = senList["always"]

outfile = open("velocitywrite.py", "w")
vel = controller.actuators["moveright"].getLinearVelocity()

if r.positive:
       controller.activate(mr)
if a.positive:
    outfile.write(vel)

Thanks sooo much,
amartin7211

The mr has this properties
print(dir(controller.actuators[“moveright”]))
gives


['__class__', '__delattr__', '__doc__', '__eq__', '__format__', '__ge__', 
'__getattribute__', '__gt__', '__hash__', '__init__', '__le__', '__lt__', 
'__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', 
'__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'angV', 'dLoc', 
'dRot', 'damping', 'executePriority', 'force', 'forceLimitX', 'forceLimitY', 
'forceLimitZ', 'invalid', 'linV', 'name', 'owner', 'pid', 'reference', 'torque', 
'useLocalAngV', 'useLocalDLoc', 'useLocalDRot', 'useLocalForce', 
'useLocalLinV', 'useLocalTorque']

and no getLinearVelocity to be seen, you probably have to compute it out of available values?

This was the ‘easy motion’ the other possibility has to be checked too …

To get the linear velocity of a moving block, simply get the linear velocity of that block:


import bge
block = bge.logic.getCurrentScene().objects['Block']
block_LinV = block.worldLinearVelocity

Let the actuators and other logic things do their stuff and simply concentrate on the object that you want to record.

Or before 2.5x:


import GameLogic
block = GameLogic.getCurrentScene().objects['OBBlock']
block_LinV = block.worldLinearVelocity

The issue that you’re encountering is because you are trying to get the linear velocity of an actuator rather than the object itself.

Great! Thanks! I really appreciate the help.