Help: AttributeError

I was running a script, and I got this error message.

AttributeError: not a sequence type, expected a sequence of numbers size 3

Does anyone know what this means? I’m pretty sure It has something to do with obj.setPosition.


import GameLogic 
 
cont = GameLogic.getCurrentController() 
obj = cont.getOwner() 
 
pos = GameLogic.globalDict["playerPosition"] 
print pos 
obj.setPosition([pos[0])

globalDict[“playerPosition”] is equal to obj.getPosition from another script.

Looks like you cant use something like this

obj.setPosition(pos[0])

use this instead

obj.setPosition(pos)

or

obj.setPosition(pos[0][0][0])

anyway this method is deprecated

If it’s deprected, is there another way to do it? Also, I changed the error message by using (pos[0],pos[1],pos[2]) as the setPosition. However, now I got this error message.

‘builtin_function_or_method’ object is unsubscriptable

Any ideas?

This is using Blender 2.49.2 and Python 2.6.2 …

My problem is setting the position of an object based on it’s previous position. While I appreciate the .blend, It does not address my problem.

Just store the players position in the global variable and call it when needed. You may need to post a blend to get more help.

http://blenderartists.org/forum/showthread.php?t=160816

Here is an example using two scripts…

position, worldPosition, localPosition (and the depricated setPosition()) expect a list with 3 numeric items. If you provide a non-list you will get this error. (see http://www.blender.org/documentation/249PythonDoc/GE/GameTypes.KX_GameObject-class.html)

You can do this:

 
obj.position=[1.1, 0.0, 0.234142]  #or obj.setPosition([1.1, 0.0, 0.234142] )

referring to your first post (assuming that pos is the result of obj.getposition() from another script):

 
obj.setPosition(pos)

I hope it helps

Heres the .blend of an example using my script.

Attachments

GameSaveLoad.blend (130 KB)

Here is a working setup with your scripts. There was a problem using getPositon() instead of using obj.position.