import bge, os
def firstload():
g = bge.logic
s = g.getCurrentScene()
proxyobj = s.objectsInactive["proxyobj"]
filename="Weapons"
elenco = bge.obj_data
#add the library
path = g.expandPath("//") #the path of the runtime/blend
sep = os.path.sep
file = path + "Data" + sep + "Obj" + sep + filename + ".blend"
try:
g.LibLoad(file,"Mesh")
except:
pass
current_list = elenco.keys()
current_list = sorted(current_list)
bge.obj_added= []
for n in current_list:
infos = elenco[n]
if str(infos[1]) == str(s):
objadded = s.addObject(proxyobj, proxyobj,0)
objadded.worldPosition = infos[2]
objadded.worldOrientation = infos[3]
objadded.replaceMesh(infos[0])
objadded["item"] = 1
objadded["nome"] = str(infos[0])
bge.obj_added.append(objadded)
this add a list of objects
instead, this other funtion should delete the nearest object…
for ob in prinobjlist: #search for all the possible object to add in the list that is created when Loader Module put all the objects in the scene
#get the distance from the character
distance = ob.getDistanceTo(o)
try: #control if the object can be picked up
ob["item"]
except:
ob["item"] = 0
if distance <= 4.000 and ob["item"] == 1: #if the object is enough near
nearobjlist.append(ob)#add to the list of the legal objects
if nearobjlist != []:
#print(nearobjlist)
ob = find_nearest(o.worldPosition,nearobjlist) #find the nearest object
...
do things
...
print(bge.obj_added)
print(ob)
#obindex = bge.obj_added.index(ob) (1)
#del bge.obj_added[ob] (2)
ob.endObject() #delete the object from the scene
print(ob.endObject())
def find_nearest(point,list):
nearest = None
old_dist = None
for obj in list:
dist = (point - obj.worldPosition).length
if not old_dist or old_dist > dist:
nearest = obj
old_dist = dist
return nearest
The console prints
[proxyobj,proxyobj]
proxyobj
None
and the object is not deleted from the scene…
In addition, (1) and (2) gives error, without saying why it’s raised…
Any idea on how to solve?
Thanks