Use python to get the key of the item that an item is parented to?

I need to get the key of a object that another object is parented to,

I used google, but the terms generated 1,000,000’s of results, none what I need

Item Bob is parented to Sam,

So trigger--------------->(Bob wonders who he is parented to with python)
Bob([“Parent”] = Sams UUID Key

so Bob.parent I think is my answer… but I am not sure if that is just the name or key…

I am triggering Bob with a collision with “trigger”

how do I get the last Item bob collided with?

I seriously doubt you went through 1 000 000 search results.

Anyways, by searching through any API documentation, you can find the correct syntax and code for whatever you want to program.
http://www.blender.org/documentation/blender_python_api_2_64_9/

That’s my favourite one.

Good luck.

All I do is answer people here, and ask questions, and then sharing leads to me getting a better understanding of more then one way to do everything, but I am not the best “sit down and sift through this documentation” type guy :slight_smile:

I will help anyone, as directly as I can… as well as point them to places to learn themselves… but I did ask a very direct question :slight_smile:

I do not know why you always refer to UUID.

The parent of an object is KX_GameObject.parent

ok so…
parentThe object’s parent object. (read-only).
[TABLE=“class: docutils field-list”]
[TR=“class: field-odd field”]
[TH=“class: field-name, bgcolor: #EEDDEE, align: left”]Type :[/TH]
KX_GameObject or None

[/TR]
[/TABLE]

bob.parent

Old code dies hard…

that is a object unique identity key from secondlife,

lol

now I need the last object that triggered a collision sensor …

:no:

It’s not even sifting through pages documentation… You click one link, and the search for the word “parent”.

Like literally. You click the link in my previous post, then click on “Game Types (bge.types)” because you’re looking for KX_GameObject methods, and then you hit “Ctrl + F” and search up “parent”. It’s that simple.

It also gives you way more information on what you’re looking for.

Part of being a programmer is learning how to learn; learning how to teach yourself.

Edit:
You can do the same thing to grab the hit list on your collision sensor.

Once you have the resources, you should be able to learn how to use the API on your own. Later on, the difficulty doesn’t come from ignorance of the correct key words, but it’s more on how to put them together.

Much like an essay, putting words together is easy. What makes an essay really great is how you put those words together to express what you need to express.

I search collision… I get 210 pages

I search hit list…
I get a great result

so

KX_TouchSensor(SCA_ISensor)Touch sensor detects collisions between objects.
propNameThe property or material to collide with.
[TABLE=“class: docutils field-list”]
[TR=“class: field-odd field”]
[TH=“class: field-name, bgcolor: #EEDDEE, align: left”]Type :[/TH]
string
[/TR]
[/TABLE]
useMaterialDetermines if the sensor is looking for a property or material. KX_True = Find material; KX_False = Find property.
[TABLE=“class: docutils field-list”]
[TR=“class: field-odd field”]
[TH=“class: field-name, bgcolor: #EEDDEE, align: left”]Type :[/TH]
boolean
[/TR]
[/TABLE]
usePulseCollisionWhen enabled, changes to the set of colliding objects generate a pulse.
[TABLE=“class: docutils field-list”]
[TR=“class: field-odd field”]
[TH=“class: field-name, bgcolor: #EEDDEE, align: left”]Type :[/TH]
boolean
[/TR]
[/TABLE]
hitObjectThe last collided object. (read-only).
[TABLE=“class: docutils field-list”]
[TR=“class: field-odd field”]
[TH=“class: field-name, bgcolor: #EEDDEE, align: left”]Type :[/TH]
KX_GameObject or None
[/TR]
[/TABLE]
hitObjectListA list of colliding objects. (read-only).

this seems to only apply to touch sensors though, not collision…

Will own.hitObject work without a defined sensor?

edit

Added .blend in question

for some reason I can not get it to only trigger a script once…

help?

I still need to do the parenting stuff with the collision stuff, but for now I just need to trigger it once,

Attachments

Parenting.blend (521 KB)

What? How’d you get 210 pages of results? Are you using the documentation page?
Because I searched up collision on the page (using it’s search function) and I didn’t get that many.

Anyways, “hitObject” is a method on sensors that detect collision. “hitObject” is from a totally different type of class, it’s not from the KX_GameObject class.

It’s almost like trying to call worldPosition on a collision sensor.

Another thing you could do is try it out, and see if it works, then read the error in the console to figure out what went wrong. It’ll probably say something like, “hitObject” isn’t a method on this class (something along those lines).

Ok, added .blend above I meant 210 results when I searched collision,
each a link to a page,

lol right now I just need some help finding out why it calls the script infinity instead of once…

Attachments

Parenting.blend (521 KB)

You keep toggling the “stop” property. So it changes “infinitely”, so the script is triggered infinitely. All you do is disable the true pulse and the tap option on the property sensor that handles the changes in the stop property.

Ok Fixed it, Now I know I need to get the sensorname and use that to find the collided object

I have
CollisionSensor(NameOfSensor) "?

how do I use it though?

I know some scripting, but I don’t get the syntax here

obj.CollisionSensor(NameIt) ?

Please read the BGE Guide to Python coding it contains a lot of useful tips.

bill = cont.sensors[“Bob”]

print(bill.hitObject)
?

Try it out maybe? You don’t need to confirm with the forum every time you figure something out.

Like I said, start teaching yourself learning skills. There tons and tons of online resources, through video and documentation. That’s the great thing about the internet at the moment. Which ever method you prefer to learn something it’s out there; just a youtube or google search away.

If you give me anything with a collision sensor in it, that detects a hit object, I can probably not ever forgot how to use it, but this is not working, I have learned most of what I know from asking questions, and reverse engineering, could you answer my question directly rather then try and have me get lost in a 500 page document? I have dislexia and a short attention span… and I need to get this done

if I where helping you… I would make a .blend…

a file is worth a billion pictures…

found it

import bge

GL = bge.logic

cont = GL.getCurrentController()

own = cont.owner

target = bge.logic.getCurrentController().sensors[“Sensor”].hitObject