How can a player make numeric inputs to control objects?

Does anyone know of a good tutorial that shows the python code allowing a player to make a numeric input that will control an object in a scene? For example, making a cube spin by typing in the number of rotations per second. I’ve viewed many tuts that described how to capture and display text and one that captured timer information and used it in ranking scores. I haven’t seen a tutorial that showed how a number ( floating or integer ) input by a user/player could, say, move or rotate an object. Google searches using a variety of key words didn’t produce any appropriate hits.

I know a way this can be acomplished. First set up a keyboard sensor with all keys enabled and have its target be a property, say “Rot”. set the log toggle to be a bool prop. like so then add this text

import GameLogic
controller = GameLogic.getCurrentController()
own = controller.owner
Rot = own['Rot']
print(Rot)
Mot = controller.actuators["Motion"]
if Rot != "":
    Rot = float(Rot)
    Mot.dRot = (0.0, 0.0, Rot/100) 
    controller.activate(Mot) 
else:
    Mot.dRot = (0.0, 0.0, 0.0) 
    controller.activate(Mot)

and conect like so


It may take a little tweeking…

Separate your requirements:

A)

B)

So you can concentrate on each requirement and workout solutions of it. There can be several different solutions. If you keep it separate you can replace them and choose whatever fits best.

A) will output the input of B).
This requires C) the interface between A) and B)

C) should be pretty fix. Which means A) and B) depend on C). In other words: if you change C) you need to change A) and B) too. But you can change A) or B) without to change C)
So I recommend to define C) the interface first

Example:
C)
is a property called “number of rotations” type int (or float?)
it resides on the object to rotate.
This means all A) solutions need to know what object does B)

Possible solution for A):

  1. keyboard input for a string
  2. converts to number
  3. displays the number
  4. knows the object that rotates
  5. sets the property “number of rotations” with the number from 2)

Possible solution of B):

  1. if property “number of rotations”
    1.1) it stores this number in another property “rotations to go” an
    1.2) sets the property “number of rotations” to -1 (= no input)
  2. if property “rotations to go” is > 0 -> rotate
  3. if rotated one turn -> decrease property “rotations to go” by 1

I think you see you can use another implantation of A) (e.g mouse click input) without the need to change B)

but if you decide to use messages as C) you need to change A) and B)

I hope it helps

Kylona, thanks for the leg up; using your code I was able to spin my cube. Monster, good suggestions; I will apply them. My python and my python API are at the beginning stages, so I was trying to find a tutorial but with the tutorials I’ve already viewed and the info I’ve gotten here I may be able to write the code I need. Thank you both for your help.