# Trying to rename an object via keyboard input

Im trying to rename an object when I hit a key so that it overwrites an existing object with that name. I have 5 objects that each have a unique paired (trackTo) object.

if mouseOver.positive:
target = mouseOver.hitObject
if click.positive:
trackObject.worldPosition = mouseOver.hitPosition


the goal is so that when I hit 'TAB' in game, then trackObject.001 (and trackObject.002, .003, ect) all turn into that trackObject as seen above (at different times of course). thus replacing the original trackObject name with w.e else untill eventually it gets turned back into trackObject, and the cycle repeats.

I dont have much skill in python, but i seem to be getting a basic hang of things, so any help would be appreciated, also if there is an easier way of doing this, im not opposed to hearing it.

• I don't see where you are changing the tracked object's name in your script; only the position of the object that is linked to the controller is affected. This would be easier if we know what you are trying to achieve, this way one can give you a correct answer. – Yvain Dec 18 '16 at 17:19
• Alright, ill try to explain (im not very code savvy here) There are 5 units. each one needs to have its own trackObject, Hitting tab would switch which trackObject i am moving when I click. at any time if I hit space I want the 5 units to activate and goto their respective trackObjects. i hope i cleared up confusions? again sorry, im terrible at code.. – TimFromInternet Dec 19 '16 at 10:40

# Object names

Trying to rename objects is typically a sign, that you do not understand what you really want.

### Real world Example:

When you interact with a person you interact with the person not with the person's name.

It is the same with objects, you interact with the object itself.

## Search Criteria

According to your description you have a single search criteria: the name.

Where is this name coming from? Obvious when this is your criteria, you need to consider all objects matching that criteria. If you mean a certain object of the set of objects, you need to tell how you differentiate between them. Typically it is one or more other criteria.

## Object References

When you already have a reference to the object you want to interact with, there is no need to look at it's name (unless you print it to console for debug reasons).

# Analysis

I really do not understand what you are trying to achieve. Rephrasing the question might help. Here are my questions to you:

• What objects are tracking?
• What is each of that objects tracking?
• When pressing Tab what should happen (I do not understand that sentence).
• When clicking on an object, what should happen?

# Solution

You need to implement a selection operation.

• Alright, ill try to explain (im not very code savvy here) There are 5 units. each one needs to have its own trackObject, Hitting tab would switch which trackObject i am moving when I click. at any time if I hit space I want the 5 units to activate and goto their respective trackObjects. i hope i cleared up confusions? again sorry, im terrible at code.. – TimFromInternet Dec 19 '16 at 18:17
• Do I understand you right, you have 5 tracking objects and 5 tracked objects? There is a fixed 1:1 relation between a tracking and a tracked object? Do they all track at the same time (their desired tracked object), or do they start tracking on <space>? What does "switch" mean? What is the difference between the current (enabled) and the other (disabled) tracking objects? [Just now I think you are looking for a "switching" or "toggling" operation] – Monster Dec 20 '16 at 5:28
• Your other question (blender.stackexchange.com/questions/69524) gives my the answers I need. – Monster Dec 20 '16 at 5:50
• I suggest you ask another question at stack exchange. e.g. "How to switch selection on objects in-game" or so. You already have a similar question, but it asks for details on a specific solution in your mind, rather than for a solution on an higher level. – Monster Dec 20 '16 at 5:59