Entering values by keyboard


Someone knows how to make the usuary set the values of certain properties of objects, like their mass and the forces that move them?
Thanks for the help.


You’ll have to do that using a python script.

Thanks for de advice, fireside.

I tried to do a simple script to make the usuary set values by keyboard, and to print them. I want that, only by test, the usuary set a cube’s mass. Take it a look:

import GameLogic
cont = GameLogic.getCurrentController()
cube = cont.getOwner()

print "Enter with the object’s mass: "

a = raw_input()
cube.mass = float(a)

print “”
print cube.mass

I don’t know why, but it didn’t work. It can’t associate the value entered with the property “cube.mass”. If anyone can help me on understand what I did wrong, I’ll be very grateful. Thanks.

The problem is in the definition of the mass variable:

The object’s mass (provided the object has a physics controller). Read only.

It’s a read only variable, meaning you can’t change it. Unfortunately the game engine doesn’t have a setMass() function, so I’m not sure what you could do about it.

Oh, sorry fireside, I was unfortunate in choosing the name of the cubes property. I already know the objects mass cant be altered by the way I want to do. Im trying to modify a common objects property, know? I just gave the wrong name to explain it to you, in the script above. Consider that the name isnt “mass”, but “elasticity” or another thing.
However, the script dont work. I dont know why. I dont know what I did wrong. If you could help me, if you could show me a way to do this, Ill be grateful very much.

I want to thank you by all the help. Thank you very much by the “GameLogic Tutorial” you indicated to me. It was very important. Bye.

Unfortunately there isn’t a function or variable for elasticity either. I think, when it comes to physics, your going to have to check the newer game code in the physics examples, and I’m not sure where the documentation is for the bullet engine. I haven’t messed much with the newer physics code, so I really can’t help. Hopefully someone else will be able to post a link. I would start by looking at the physics examples for Blender, though.