...
...
if nearobjlist != []:
ob = find_nearest(o.worldPosition,nearobjlist) #find the nearest object
nome = ob["nome"]
obinfos= bge.obj_informations[ob["nome"]]
# print(ob)
tipo = obinfos[0]
# print(nome) #debug
# print(tipo) #debug
weight = obinfos[3]
(355) inventoryweight = totalweight()
if (arm["maxweight"] - inventoryweight - weight) > 0:
if tipo == "Item": #control the type of item
if (nome in items) == 0: #add 1 of it to the inventory if it didn't exist
items[nome] = 1
....
....
def totalweight():
g = bge.logic
c = g.getCurrentController()
o = c.owner
s = g.getCurrentScene()
prinscene = getScene("Principale")
#invscene = getScene("Inventory") /not used
prinobjlist = prinscene.objects
#invobjlist = invscene.objects /not used
arm = prinobjlist["Arm_Character"] #armature of the player
box = prinobjlist["Ch_Box"] #box of the player
inventory = arm["inventory"]
items = arm["items"]
inventoryweight1 = 0
inventoryweight2 = 0
#weight in inventor
for item1 in inventory.keys():
objinfo1 = bge.obj_informations[item1]
totalitemweight1 = objinfo1[3] * inventory[item1] #specific weight * number of that specific object
inventoryweight1 += totalitemweight1
#weight in items
for item2 in items.keys():
objinfo2 = bge.obj_informations[item2]
totalitemweight2 = objinfo2[3] * items[item2]
inventoryweight2 += totalitemweight2
return(inventoryweight1 + inventoryweight2)
Before using the bge global functions everythink was working well, but i needed to acces data from this global vars, and now it gives an error without saying which kind of error happens…
Any help?
The last time I had an issue like this I had to comment out blocks of code until I found the block that wasn’t working. It was a really obscure error.
What I would do in this situation:
Block comment all the code in totalweight.
Place a simple line print(“CALCULATING TOTAL WEIGHT”) in capitals so it is easy to see in the console.
Place return at the bottom.
def totalweight():
print("CALCULATING TOTAL WEIGHT")
'''
All current function content stays here
...
...
....
'''
return
If this runs without error then the problem is in that function somewhere. You can uncomment the code piece by piece until the error comes back and then you know where the error is and can try rewriting it or fixing it.
If this does not run without error then there is something weird happening before the function call. :eek: Hope this doesn’t happen. I had this issue and the error was something like 4 lines before the function and a nightmare to find. There could be a bug in the way you’re storing the information that the function uses. Lots of print() calls and checking of all the stored data might be necessary in this situation.