Python error, but no other infos is given

error line 355, in inventoryfunction


   ...
   ...
   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?

difficult to say, without more information.

How do you know the error is at line 355?

Is here the strangness… Usually python say much about the error, and debugging is easy, but this time it say’s quite anything…

Here’s the error


In italian i would say “Non so che pesci pigliare…”

hmm… it might be a problem at some other place.
I suggest to copy the line and do somethin like this:


print totalweight()

Check that totalweight is not overwritten earlier by a variable (e.g. totalweight = …).
If so better name it calcTotalWeight().

Just a guess

I changed name and tried the print you suggested, it gives error at the line of the function call…

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.

yeah, i deleted all the print i made to “debug” the code when i posted…
I noticed that the problem is in


objinfo1 = bge.obj_informations[item1]
  totalitemweight1 = objinfo1[3] * inventory[item1]

I’ll search if i used in the wrong way something… By the way, thanks for the help :wink: