Sneaselx
(Sneaselx)
August 11, 2009, 7:46am
1
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.
timi0
(timi0)
August 11, 2009, 8:22am
2
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
Sneaselx
(Sneaselx)
August 11, 2009, 5:24pm
3
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?
Hunter
(Hunter)
August 11, 2009, 5:46pm
4
This is using Blender 2.49.2 and Python 2.6.2 …
Sneaselx
(Sneaselx)
August 11, 2009, 6:13pm
5
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.
Hunter
(Hunter)
August 11, 2009, 6:47pm
6
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…
Monster
(Monster)
August 11, 2009, 11:15pm
7
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
Sneaselx
(Sneaselx)
August 12, 2009, 4:15pm
8
Heres the .blend of an example using my script.
Attachments
GameSaveLoad.blend (130 KB)
Hunter
(Hunter)
August 12, 2009, 4:53pm
9
Here is a working setup with your scripts. There was a problem using getPositon() instead of using obj.position.