move block in grid

I am trying to move a block in a grid pattern and I don’t no why this isn’t working.

cont=GameLogic.getCurrentController()
own=cont.getOwner()

up=cont.getSensor("up")
down=cont.getSensor("down")
left=cont.getSensor("left")
right=cont.getSensor("right")
pad8=cont.getSensor("pad8")
pad2=cont.getSensor("pad2")

x=0
y=0
z=0

if up.isPositive():
    y+1
if down.isPositive():
    y-1
if left.isPositive():
    x-2
if right.isPositive():
    x+2
if pad8.isPositive():
    z+.6
if pad2.isPositive():
    z-.6

own.setPosition([x,y,z])

I’ve got sensors with those names attached to a python controller with the file name in it.
does anyone know why this doesn’t work or if there is another way?

it should be

x = x - 1 instead of x - 1

I’ll try that. thanks

that sort of worked. because I have x=0 y=0 and z=0 in the script it sets it back to 0, how do I stop it from reseting?

either give the object properties x,y,z (then say own.z = own.z+1) or make them in GameLogic (global variable). for the 2nd way you have to check at the beginning of the script if GameLogic.z exists. Either make an initialization function to create them once (use a property as 1,0) or at the beginning of each script use the if GameLogic.hasattr(“z”) to check whether z exists (if it doesn’t, you need to create it).

I tried using properties but I don’t know how to use them in Python script. I looked all over the TutorialsForBlender3d.com python index. So can I get properties in python

to use properties in a python script use own.propname

It’s still reseting. It looks like it should work fine.

cont=GameLogic.getCurrentController()
own=cont.getOwner()

up=cont.getSensor("up")
down=cont.getSensor("down")
left=cont.getSensor("left")
right=cont.getSensor("right")
pad8=cont.getSensor("pad8")
pad2=cont.getSensor("pad2")

x=own.x
y=own.x
z=own.x

if up.isPositive():
    y=y+1
if down.isPositive():
    y=y-1
if left.isPositive():
    x=x-2
if right.isPositive():
    x=x+2
if pad8.isPositive():
    z=z+.6
if pad2.isPositive():
    z=z-.6

own.setPosition([x,y,z])

print x,z,y

What’s going on here?:confused:

you are now setting the position to the variables xyz so every time it runs it changes xyz to = own.xyz and then it changes the xyz=xyz then it runs and own.xyz still equals 0 so change the x = x + 1 to own.x = own.x + 1
here…

cont=GameLogic.getCurrentController()
own=cont.getOwner()

up=cont.getSensor("up")
down=cont.getSensor("down")
left=cont.getSensor("left")
right=cont.getSensor("right")
pad8=cont.getSensor("pad8")
pad2=cont.getSensor("pad2")

x=own.x
y=own.y
z=own.z

if up.isPositive():
    own.y=own.y+1
if down.isPositive():
    own.y=own.y-1
if left.isPositive():
    own.x=own.x-2
if right.isPositive():
    own.x=own.x+2
if pad8.isPositive():
    own.z=own.z+.6
if pad2.isPositive():
    own.z=own.z-.6

own.setPosition([x,y,z])

print x,z,y

edit: all xyz all = own.x
just tested and it works