[Python] Ray.hitObject problem

Ok, so I’ve been trying to get a property status from an object that a ray collides with.
So this sounds a little confusing, but basically:

  • object1 shoots out a ray
  • the ray hits object2 with the property ‘boolean’
  • object1 stores the name of the hit object (object2)
  • object1 finds the name in scene.objects(stored_name) and assigns this to ‘status’
  • if status[‘boolean’] == True —> do stuff

However the line ‘status = scene.objects(stored_name)’ does not work

Why can’t I just use scene.objects[‘object2’] ?
because there will be more than one ‘object2’.

Use [] instead of ()
This brings up a CList key error
using ordinary brackets brings up CList Value error (not callable)

So to give it a little context and make it possibly less confusing I created a small (not working) .blend:
president_distress.blend (497 KB)

The ‘president’ = object2
The ‘guard’ = object1
I’ve also annotated the script

In short (without using python necessarily):
I need one object (object2) to send out a distress signal
I need the other object (object1) to respond by moving to the distressed object.

If anyone could come up with a solution for getting scene.objects to work or another alternative such as suggested above that would be greatly appreciated! :smiley:


Oh I see. You used VIP = scene.objects[President] as President was declared at the top equal to “”, when you should have used VIP = scene.objects[own[‘pres_name’]], making it the new value.

Also you had this if VIP[‘distressed’] == True: and you should have had this if VIP[‘distress’] == True: because the property was named distress.

Edit: This gives no errors, but it still doesn’t work… Hopefully this can be a good starting point though.
Edit 2: I noticed that that was only because distress was false. I changed it to true and it works, I assume you’ll be changing that back and forth so yeah it works :slight_smile:

Awesome! thanks a lot :smiley:

Also, don’t check for things equal to Boolean. Most objects have a bool method which describes the boolean representation of the object, and often you’re storing booleans themselves. The if statements checks for the statement’s value equalling True anyway, so you’re essentially writing:

if True == True, rather than, if True:

It’s an honour to help!