help updating teleport error

As i’m not making progress with the ledge/hange issue, i’ve implimented this teleport script which works perfect.

I just need help rewriting it to make it work without this error popping in console:

Python script error from controller “cont#CONTR#1”:
Traceback (most recent call last):
File “teleport”, line 23, in <module>
AttributeError: ‘NoneType’ object has no attribute ‘setPosition’

Here’s the code as it appears in my game.

import GameLogic as GL
cont = GL.getCurrentController()
sc = GL.getCurrentScene()
own = cont.getOwner()
touch = cont.getSensor('touch')
burst = cont.actuators['teleburstmsg']
if touch.positive:
 
 cont.activate(burst)
 
 
destName = "OB" + own.destination
kuro = touch.getHitObject()
toloc = sc.getObjectList()
destObj = toloc[destName]
kuro.setPosition(destObj.getPosition())

I’m using 2.49 with ogg support and python 2.6.2

Thanks.

Kuro

Strange, there isn’t an obvious line 23, however I wonder what it’d be like if you indented everything after the ‘if’?

Keep in mind the script works as intended in game.

it’s refering to this line: kuro.setPosition(destObj.getPosition())

This somehow got messed up when i copy and pasted into post.

I tried indentation of logic into if statment which rendered script useless, i’m just wondering if i could rewrite this line better for python to get rid of the error msg?

touch gets created by:


kuro = touch.getHitObject()

and since the error states that kouch[/] is a NoneType, i’d suggest [I]touch doesn’t have a hit object, so you need to check for that case (I was thinking that that ‘if’ was doing that)

It seems like the only problem is your indentation.

Try this:



import GameLogic as GL
cont = GL.getCurrentController()
sc = GL.getCurrentScene()
own = cont.getOwner()

touch = cont.sensors['touch']
burst = cont.actuators['teleburstmsg']

if touch.positive:
    cont.activate(burst)
    destName = "OB" + own.destination
    kuro = touch.getHitObject()
    toloc = sc.getObjectList()
    destObj = toloc[destName] 
    kuro.setPosition(destObj.getPosition())

Yours works in game as well Ex, but i now get this error in the console for the last 3 lines of code:

Method getHitObject() is deprecated, please use the hitObject property instead.
teleport:12
Method getObjectList() is deprecated, please use the objects property instead.
teleport:13
Method getPosition() is deprecated, please use the position property instead.
teleport:15
Method setPosition() is deprecated, please use the localPosition property instea
d.
teleport:15

Here’ the lines i think the console is refering to(In bold):
kuro = touch.getHitObject()
toloc = sc.getObjectList()
destObj = toloc[destName]
kuro.setPosition(destObj.getPosition())

Btw, great to hear from ya again, been waaaay to long.

Right, I didn’t remember if those were depreciated in 2.49.

This should fix those:

import GameLogic as GL
cont = GL.getCurrentController()
sc = GL.getCurrentScene()
own = cont.owner
touch = cont.sensors['touch'] 
burst = cont.actuators['teleburstmsg']  
if touch.positive:
     cont.activate(burst)
     destName = "OB" + own.destination
     kuro = touch.hitObject
     toloc = sc.objects
     destObj = toloc[destName]
     kuro.position = destObj.position


Are you still working on that game project?
Ex.

Yep, life just gets in the way sometimes. I need some serious help with my ledge\hang, i’ll P.M. ya with the details if don’t mind Ex.

Woo hoo your changes worked, i owe ya another one Ex(Not to mention being my python sensei from the beginning.:slight_smile: ). thanks.

Sure, feel free to PM me with any questions!
Ex.