spawn down problem again

What does this mean?Here is the script to.

Python script error - object 'Empty', controller 'Python':
Traceback (most recent call last):
  File "C:\Users\barbara\Desktop\endless_runner_v1.2a.blend\", line 60, in create
SystemError: gameOb.getDistanceTo(value): KX_GameObject, Blender Game Engine data has been freed, cannot use this python variable
Blender Game Engine Finished

import random

def create(cont):
    own     = cont.owner
    scene   = own.scene
    if not 'last_added' in own:
        own['added_before'] = []
        own['last_added']   = None
        own['ground_objects'] = [obj for obj in scene.objectsInactive if 'ground' in obj]

    player              = scene.objects['player']
    ground_plane_size   = 30.0 # Y direction / used as an offset
    ground_plane_down   = -3.0 
    spawn_distance      = ground_plane_size /2 # min: of choice, max: ground_plane_size (from origin)
    remove_distance     = ground_plane_size  # min: ground_plane_size , max: of choice (from origin)
    spawn_distance2      = ground_plane_down /8 #
    remove_distance2     = ground_plane_down 
    # origin = the orange dot you see when you have an object selected, move object in edit mode(tab)
    # to change the origins position, or select all and hit shift+s then 3d cursor to selected and in 
    # object mode select the object hit ctrl+shift+alt+c and place it at the 3d cursor to center it.

    # it is used at to check distances, so if things go wrong check the origin/distances 
    # i suggest to keep the origin at the center and at the top of the ground plane
    if own['last_added']:

        distance_to_last_added  = player.getDistanceTo(own['last_added'])
        random_height           = random.choice([-1, 0, 1]) # ground plane spawn heights
        if distance_to_last_added < spawn_distance: 
            own.worldPosition.y += ground_plane_size
            own.worldPosition.z = random_height

        if distance_to_last_added < spawn_distance2: 
            own.worldPosition.z += ground_plane_down
    if own['added_before']:
        for obj in own['added_before']: 
            distance_to_added_before = player.getDistanceTo(obj)
            if distance_to_added_before > remove_distance: 

def add_object(cont):  
    own     = cont.owner
    scene   = own.scene
    added_object = scene.addObject(random.choice(own['ground_objects']), own, 0)
    if own['last_added']:    
    own['last_added'] = added_object   

either “gameOb” or “value” refer to game objects that you removed before.

How would i remove it?

you are trying to get a distance to an object that has been ended (obj.endObject())
in your case own[‘last_added’] does not exist anymore.

but trying your code it does not give me an error, but it does not spawn anything downwards either.
due to you cannot move an empty to 2 different locations in a single frame to spawn 2 objects at the same time.

That why i said, to copy the script and copy the empty, then adjust 1 script to spawn downwards.
then you can spawn 2 items at the same time.

You have to dig downwards by putting a collision sensor on each plane with property pop on it.which is connected to a end
objects actuatuator.Then parent a empty to the player.Make a sphere with the property pop on.Then place it on a hidden layer.Then put on the empty parented to the player a keyboard sensor with z on it.Which is connected to a add object actuator which adds the sphere with the pop property.Then you get the error.When you fall.

i did what cotax posted.But when i try to dig with spheres.The ground plane does not end.Here is the blend.Press x to spawn spheres to dig.


endless_runner_v1.2a.blend (569 KB)

Change the floor plane, collision property names, and the sphere property name, then it works. probaly used a white space somewhere.

dont forget, when you delete the plane you need to remove it from the list with python as well

you dont have to change the script variables, the core code works due to its an other empty you use it with so own[‘last_added’]. etc. can stay how it is no need to add 2 behind.

as i said before i dont going to build it for you, but you can better analyse the script and if you dont know what something does, ask. this way you learn how it(scripting) works.

The property pop had a space at front that is why it did not work.
Now i need to find out how to dig on any of the ground.