import GameKeys as gk
import GameLoic as g
cont = g.getCurrentController()
keys = cont.getSensor('Key')
keylist = keys.getPressedKeys()
#print gk.UKEY
if keys.isPositive():
for key in keylist:
print key[0]
if key[0] == 146:
print "u"
the script works but i allways got this message in consol :
PYTHON SCRIPT ERROR:
Traceback (most recent call last):
File "Variables.py", line 11, in ?
TypeError: iteration over non-sequence
146
u
import GameLoic as g
cont = g.getCurrentController()
keys = cont.getSensor('Key')
keylist = keys.getPressedKeys()
if keylist:
if key[0][0] == 146:
print "u"
and the iteration over non sequence means youre trying to loop through sometyhing that is not a list because you have to chack and make sure there is a list before you loop it
import GameLogic as g
cont = g.getCurrentController()
keys = cont.getSensor('Key')
keylist = keys.getPressedKeys()
if keylist:
if key[0] == [146,1]:
print "u"
That way, it only prints one “u” per keypress ([146,1] means the key is being pressed this frame, [146,2] means the key is held this frame, [146,3] means the key is released this frame).