A slight dilemma (in HD video format)

If you hate embedded videos:


Any advice is apreicated…
.blend is attached…
thing.blend (461 KB)


import bge
import mathutils

mu = [0,0,0]

def lal():
    global mu
    cont1 = bge.logic.getCurrentController()
    own1 = cont1.owner
    own1.worldPosition = mu


def dest():
    global mu   
    cont = bge.logic.getCurrentController()
    own = cont.owner
    mu = own.position

Do not use position it is deprecated and incorrectly implemented.

The code looks a bit strange. It looks like you try to mix module mode and script mode. I guess that is because you just switched from one mode to the other. Better avoid that. It will not give you an happy-end ;). Try this structure:

Module mode (recommended):

import bge

storedPosition = [0,0,0]

def restorePosition(cont):
    own = cont.owner
    own.worldPosition = storedPosition 
def storePosition(cont):
    global storedPosition
    own = cont.owner
    storedPosition = own.worldPosition

Script mode makes no sense here because:

  • you set the position with the stored one and overwrite the stored position with the just set one
    (mu==[0,0,0] -> location=mu== [0,0,0] mu=location == [0,0,0]).
  • the stored position will be gone after leaving this script call.

Your function names do not let me guess what this function should do, so I can’t really offer much help on this.

Module file names always end on .py :wink:

YES! thank you!!! It worked!