0

OK i'm in blender and i want to make it where if the player hits an object that has a property of lets say "box" then the game can tell my HUD [Heads up display] scene to add +=1 to its property. but i don't want to have to add a lot of logic bricks. iv tried to to use one collision logic brick to see if i could get its property but it didn't work out. here's the code i made

itemType = cont.sensors['itemType'] 

type = itemType.hitObject

if ['box'] in type:
    print("Box")

I tried to print some string to see if it would work but it never would print.

6
  • 3
    try removing the square brackets if 'box' in type:. Commented Nov 18, 2013 at 18:22
  • Please put a print(type) before you if-statement and let's see the output. Commented Nov 18, 2013 at 18:23
  • 3
    type is a builtin function, you should not replace it. Commented Nov 18, 2013 at 18:30
  • it worked i put print(type) if 'box' in type: print("it worked") and on the system console it printed " CubePickup" and "it worked" Commented Nov 18, 2013 at 18:31
  • 3
    Now that your code works & your problem is solved, add the solution to this question yourself & then accept it. Or maybe @tMJ should make his comment as an answer. Commented Nov 18, 2013 at 18:37

1 Answer 1

1

By typing in, if ['box'] in type:, your code is basically trying to search for a list containing a single element 'box' in it. i.e, ['box'].

What you actually want to do is, you want to find the element 'box' in your list, and hence you should remove the square brackets. if 'box' in type:

P.S. Although you can, but it is not a good practice to use the names of built-in functions as variables or redefine them, unless if you want to do that explicitly. You have done so with the bulit-in function type().

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.