Alright, so I’ve been puzzling over this for quite a while, and I just cannot figure out the problem. I’m working on a project (in case it wasn’t obvious… ), and I can’t seem to get the frontend for my inventory system to function correctly. Here’s a video I made that showcases the issues. I feel like I’d just confuse everyone if I tried to explain it in text.
I know the problem isn’t in my backend programming, as the debug output proves that that is working fine. Here are the scripts that do most of the work:
The backend code, which works fine:
from Util import * #This allows us to use:
# random (Module)
# math/mathutils (Modules)
# bge (GameEngineModule)
# globalDict (GlobalDictionary)
# cont (CurrentController) ##Causing issues
# scene (CurrentScene)
# cam (ActiveCamera)
# own (ControllerOwner)
# And all my other functions.
##NOTE: Every 'Collectible' object MUST have these Properties:
## Collectible[Bool]: Defines the object as something that can be collected
## Class1[Str]: Item basetype; may be 'Tool', 'Material', or 'Misc' (may be made Int later)
## Class2[Str]: Item subtype, E.G. 'Food', 'Weapon', etc. (may be made Int later)
## CanDispose[Bool]: Determines whether or not the item can be disposed (may be removed)
## Desc[Str]: The item's friendly description
cont = bge.logic.getCurrentController()
for i in cont.sensors['Collision'].hitObjectList: #Iterate over every Collectible object
if i['Collectible'] == True: #Make sure the item is set able to be collected
try: #Update the dictionary. This is a weird block of code, but necessary (I /think/) to prevent errors.
globalDict.update({i.name:{'quant':globalDict[i.name]['quant']+1, 'class':i['Class1'], 'subclass':i['Class2'], 'disposable':i['CanDispose'], 'desc':i['Desc']}})
except:
globalDict.update({i.name:{}})
try:
globalDict.update({i.name:{'quant':globalDict[i.name]['quant']+1, 'class':i['Class1'], 'subclass':i['Class2'], 'disposable':i['CanDispose'], 'desc':i['Desc']}})
except:
globalDict.update({i.name:{'quant':0}})
globalDict.update({i.name:{'quant':globalDict[i.name]['quant']+1, 'class':i['Class1'], 'subclass':i['Class2'], 'disposable':i['CanDispose'], 'desc':i['Desc']}})
finally:
#print(globalDict)
#print()
bge.logic.sendMessage("Collected", "Item {0} has been collected".format(i.name), i.name)
cont.activate(cont.actuators['SaveDict'])
cont.deactivate(cont.actuators['SaveDict'])
The frontend code, in charge of actually populating the inventory menu:
from Util import *
import ObjRefOffsetHandler2
cont = bge.logic.getCurrentController()
own = cont.owner
scene = bge.logic.getCurrentScene()
for obj in own.children:
obj.endObject()
for i in globalDict.keys():
print(i) #For debugging
if not i.startswith("SETTING"): ##Definitely NOT the best way to do this, but it's all I can think of for now.
if globalDict[i]['class'] == "Tool" and own['Subset'] == 0:
scene.addObject(i, "ObjectRef").setParent(own, False)
ObjRefOffsetHandler2.UpdateOffset()
elif globalDict[i]['class'] == "Material" and own['Subset'] == 1:
scene.addObject(i, "ObjectRef").setParent(own, False)
ObjRefOffsetHandler2.UpdateOffset()
#ObjRefOffsetHandler2.UpdateOffset()
print(globalDict) #For debugging
print() #
#bge.logic.sendMessage("ResetOffset")
ObjRefOffsetHandler2.ResetOffset()
Now, maybe I’ve just been staring at it for far too long and missed something obvious, but I absolutely cannot figure out what’s failing.
Oh, and before anyone says anything, I know that actually recreating 3D objects is not the most efficient way to do an inventory menu, but believe it or not, I actually have a good reason for doing it that way (plus it was easy ).
I’ll attach my source .blend, in case you want to look at / mess with it further. Note that it is only a tech demo, a small piece for a far larger project.
Oh, and if anyone could tell me why packed fonts don’t seem to want to work, that would be appreciated, too.
Thanks in advance for any help!