checking for objects

right, this is one hell of a question

how, with python, would i be able to check for ALL objectsincluding added objects

then i would like to check the list for objects that have a certain property
and then check their distance from the object that called the script

i want the script to then check which object is closest, and depending on that Track it, the track to actuator will probably be useless, so this will require maths. then once the relative( to local rotation vectors ) direction vector has been gotten, i’d like to see if someone can help with setting coverage for that turret.

i’m afraid i don’t know too much about python scripting, so if someone would link me to some good scripts to learn from, and some tutorials and
perhaps a list of available commands, and the different structures, like for instance object lists, mesh data, properties of objects and all that.

currently i’m pretty much in the dark


the distance and property can probably done with a near sensor
i would need the list of objects the near sensor “approved”

Why should trackto useless? With python you can change the target on the fly.

My experience with 2.37 was that added object all have the same name. So it would be difficult with the classic way: GameLogic.getCurrentScene().getObjectList()[“OBCube”]

Here you can find the game logic reference:
it includes some examples

Monsters right in 2.37 all added objects did use the same name, i had a way of “getting” them which was to put all the objects in the scene in a list, i had 5 objects in my scene which were always there so as soon as the list got longer than 5 i knew these were the added objects,

hope that helps ill try and dig the code out if you want :slight_smile:

please do, i could use any help :smiley:

and monster, thanks :smiley:

i’ll have to find out how orientation works
hmmm, far easier to use vectors , oh well

setangularvelocity might be of use

Hi sorry about the long wait ive been having trouble with blue screens on my laptop :slight_smile:
i havent tried this out yet ive just cut and pasted the relevant pieces from an old script it should work ok.

addtube is an addobject actuator

GameLogic.emitted = [] #put this in an initialise script(run it only once)

##i had 15 other objects ie cameras and empties that i didnt want to access##

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

oblist = scene.getObjectList()

if [whatever then emit something]:
##include this bit inside your if statement
lastob = addtube.getLastCreatedObject()

oblist15 = len(oblist)-15 #object list length -15 = the number of emited objects
oblist15x = oblist15-(oblist15*2) #makes the number negative for later on

if len(oblist)>15:
for ob in range(oblist15x,-1):
print ob
emmitted_object = GameLogic.emmitted[ob]

  ##now do something fruitful with the objects##

Good Luck with he rest Spike(1907 i think) has recently posted a script about setting orientation :slight_smile:

oblist = scene.getObjectList()
so that basically is the list for all objects currently active in your scene?
heh, this is useful :smiley:

i assume for( or while ) statements work in python?

i would simply have it cycling through all objects, checking for properties and distance
save the best object( determined by distance and if it is within our “cone” of detection ) as a seperate var, and use it from there :smiley:

this makes matters a bit more understandable

‘for’ statements definatly work but I’ve heard ‘while’ statements tend to crash blender.

oh joy, my first little python scripts, not using the knowledge from here, BUT they are useful, and a precursor for more to come :smiley:

first one is a custom damping script, adding some control over the motion damping* meaning you could for instance jump into water and be experiencing much more damping* * or from space into an atmosphere*

##blatantly stolen from another topic -_-' , although i had to fix some stuff
def mat_transpose(m):
   return [[m[0][0], m[1][0], m[2][0]],
      [m[0][1], m[1][1], m[2][1]],
      [m[0][2], m[1][2], m[2][2]]]
def vec_transform(v, m):
   return [v[0]*m[0][0]+v[1]*m[0][1]+v[2]*m[0][2],

import GameLogic as g
c = g.getCurrentController()
obj = c.getOwner()
vel = obj.getLinearVelocity()
ori = obj.getOrientation()

localvel = vec_transform(vel, mat_transpose(ori))

impulse = vec_transform(  [-(localvel[0] * obj.damp ), -(localvel[1] * obj.damp ), -(localvel[2] * obj.damp) * 0.2], ori) 

## notice the obj.damp and 0.2 above? the obj.damp is a damping factor *0.2 is a good value for it*
## and the 0.2 is basically a multiplier to the amount of damping felt on that local axis in the form of X Y Z, Z is the front of my object

obj.applyImpulse( obj.getPosition(), impulse )

## apply the damping

a little speed script, setting the amount of force taken by using a property

import GameLogic as g
c = g.getCurrentController()
obj = c.getOwner()
Forward = c.getActuator("Forward") ## link the python script to a motion actuator called Forward
output = 20*obj.speed ##multiply the property speed by 20 to get the wanted force
Forward.setForce( 0,0,-1*output, 1 ) ## set the force in the Forward actuator
##g.addActiveActuator( Forward, 1 ) ## don't trigger our force by the python script, use an always sensor independently for that, just make sure that the Forward actuator is connected to the true trigger and the python script