2.4 to 2.5 script transfer difficulties...

I was following a tutorial that was originally meant for Blender 2.4x, but I was using Blender 2.58a.
So, there is a script that was used to pick up an object when the crosshairs of the player are on an object with a property. I can’t get this script to work in Blender 2.58a because the system console keeps giving me this error:
ValueError: sensor.getButtonStatus<int>: Mouse Sensor, invalid button specified!

Here is the script:

import GameLogic
cont = GameLogic.getCurrentController()
own = cont.owner
ray = cont.sensors['ray']
click = cont.sensors['click']
item = own['item']
status = click.getButtonStatus(182)
if ray.positive:
 pos = ray.hitPosition
 hit = ray.hitObject
 if status == 2 and item == False:
  own['item'] = True
  hit.setParent(own, 0, 1) 
 if status == 3:
  own['item'] = False
  hit.removeParent()

I added the “import GameLogic” part.
Why am I getting this error?

Link to tutorial: http://www.youtube.com/watch?v=evlGAroMfUE

You didn’t have to add the GameLogic line, but Blender 2.5 doesn’t use the GameLogic module at all - here’s the script fixed.


from bge import logic
cont = logic.getCurrentController()
own = cont.owner
ray = cont.sensors['ray']
click = cont.sensors['click']
item = own['item']
status = click.getButtonStatus(182)
if ray.positive:
 pos = ray.hitPosition
 hit = ray.hitObject
 if status == 2 and item == False:
  own['item'] = True
  hit.setParent(own, 0, 1) 
 if status == 3:
  own['item'] = False
  hit.removeParent()


I would replace that number (182) with a value from the bge.events module (for example, bge.events.MOUSELEFTBUTTON, I think). That script should work.

In Blender 2.5 the button number was changed form 182 to 189.

Edit:
@ SolarLune.

You didn’t have to add the GameLogic line, but Blender 2.5 doesn’t use the GameLogic module at all

That is not correct. The GameLogic module is still present in Blender 2.5x. The only difference between Blender 2.49b and Blender 2.5x is that you must import the GameLogic module in Blender 2.5x.

bge.events.MOUSELEFTBUTTON is wrong use bge.events.LEFTMOUSE

Attachments

grab.blend (412 KB)

Thank you. I just had to change the 182 to 189 to fix it.