Creating a list of objects with a certain property

@superflip - Blender most likely will add objects to the destination list as it finds them in the source list. It will probably place the bags in the order that they were created in Blender, though I’m not sure on this. If you want to sort them yourself, you can do so.

@3D solar system builder - After you press Print Screen (prtscn on your keyboard), you will have to paste the image into an image editing program. Basically, the computer takes the screen and makes a screenshot out of it, putting it to the clipboard. You have to then paste it somewhere and save it - then you can upload the result.

Blender forum wont let me upload a picture.

Heres my blendhttp:http://www.pasteall.org/blend/13492

Hey SolarLune i posted my blend.Would you look at it.

Fixed it. You were using a Near sensor, not an Always sensor. The Near sensor only triggers if it nears an object with the property specified (or any object if no property is specified). The script also doesn’t work out-right in your scene - I fixed it up so that it would. The console will print two lists - the first will be any object with the ‘slot’ property, which the main game object has. The other will be empty, as the script specifies to make the second list from objects with a ‘used’ property, which the main game object doesn’t have.

Detected GL_ARB_texture_cube_map
Detected GL_ARB_multitexture
Detected GL_ARB_shader_objects
Detected GL_ARB_vertex_shader
Detected GL_ARB_fragment_shader
Detected GL_ARB_vertex_program
Detected GL_ARB_depth_texture
Detected GL_EXT_separate_specular_color
Blender Game Engine Started
[Cube.001] []
Blender Game Engine Finished
Blender Game Engine Started
[Cube.000, Cube.001] []
[Cube.000, Cube.001] []
Blender Game Engine Finished
Blender Game Engine Started
[Cube.002, Cube.000, Cube.001] []
[Cube.002, Cube.000, Cube.001] []
[Cube.002, Cube.000, Cube.001] []
Blender Game Engine Finished
Blender Game Engine Started
[Cube.003, Cube.002, Cube.000, Cube.001] []
[Cube.003, Cube.002, Cube.000, Cube.001] []
[Cube.003, Cube.002, Cube.000, Cube.001] []
[Cube.003, Cube.002, Cube.000, Cube.001] []
Blender Game Engine Finished
So this is what you got in your blender console.I duplicated what was left of the cube
a couple of times.Just checking to be sure.

Yeah, that’s correct.

The order within a list is the order they are placed in the list. I recommend to see lists returned from the BGE API as unsorted.
If you wish a different order you need to sort them. Please check the Python docs for details.

since this thread is still goin i suppose ill ask another related question…Im using the list to get the object i want but when i try to use the object ill get an error…I think im missing a step. Example:


objects_with_property = [ob for ob in scene.objects if 'slot' in ob]
true_used = [gobj for gobj in objects_with_property if "used" in gobj and gobj["used"]==True]
 
##This is my script from earlier....works fine....but if i try say, this
 
true_used.worldPosition = logic.mouse.worldPosition
 #
 
 
 

throws an error and wont work properly…wondering if im missing a step

And about the order of the list, notice how his made the list in a weird order also :D…