setParent and removeParent troubles

Hello, BlenderArtists.org! I’m rather new to blender (actually, I lied, I played around with it a few months ago and was [sadly] the only scripter in a game project that died out, as a result, I lost interest and stopped using Blender. Not to mention the complete switch-over to Slackware Linux wiped my drive…) I decided to take up Blender again due to a recent obsession with some indie games like Minecraft and Blockland. I want to make something kind of similar to it, but kind of similar to GMod, too. Heh.

Now on to the point:

I’m having a bit of trouble with a little script that sets and removes the parent of a cube (Aptly named “Cube”) to another cube (Cube.001) on left-click (using a sensor named “lclick”) and removes the parent on right-click. However, I can’t seem to get the removing part to work.
Here’s the code…

import GameLogic as g
cont = g.getCurrentController()
own = cont.owner

m1 = cont.sensors["lclick"]
m2 = cont.sensors["rclick"]

if m1.isPositive:
     own.setParent("Cube.001")

if m2.isPositive:
     own.removeParent()

Two sensors named lclick and rclick each set to Mouse[left button] and Mouse[right button], respectively, attached to a Python type controller running the script.

I have it to where Cube.001 is circling Cube, in case you were wondering how I could tell if it didn’t work or not… hehe.

Now, I don’t know if it has something to do with how my brain works, but this seems to make sense, in my head, anyway, yet it doesn’t work. Any help with this little setback would be much appreciated!

~Grubb :cool:

Anyone? I would rather like to fix this problem!

I made an example file for you.
Methodes Index http://www.tutorialsforblender3d.com/GameFunctions/GameLogicPage1.html
positive http://www.tutorialsforblender3d.com/GameModule/ClassSCA_ISensor_5.html
setparent http://www.tutorialsforblender3d.com/GameModule/ClassKX_GameObject_31.html

Attachments

Parent_Python.blend (140 KB)

Oh… Alright! I get it now. Thank you for the reply, it helped greatly. And the links were so helpful I bookmarked the site. Thank you again! On with the project!

~Grubb