This is fairly advanced, but here’s how I like to do it. As stated above, Python knowledge is a must for something this complex.
First, I create an external .json file (rename the .txt of your text file to .json, Windows will warn you that this changes the filetype, but this is what you want so do that). I start writing it as a dictionary, and fill it with little dictionaries that make up the items themselves. Here’s an example:
{
"weapons":{
"magic_sword":{"cost":500, "attack":8, "durability":50, "effect":"shoot_magic"}
},
"armor":{
"iron_armor":{"cost":500, "defense":5, "durability":20, "effect":"none"},
"mage_robes":{"cost":75, "defense":1, "durability":8, "effect":"magic_boost"}
}
}
In my main game code, I import json at the top of my script (with “import json”), and like this, tell my script to find the file and translate it:
import json
filePath = bge.logic.expandPath("//files/") # PLEASE NOTE: For this to work, your file needs to be in a folder called "files" in the same directory as your .blend file!!
dict_itemlist = json.load(open(filePath+"itemlist.json", "r")) # Also note, this assumes the file is called "itemlist.json".
I use json because it directly translates to usable code, without any extra unnecessary steps such as literal_eval, which can glicth fairly easily and takes up a lot of runtime resources.
So, with every project I start up, I have a “setup” script run at runtime that runs any code-required function I need to have happen. In this instance, we need to save this .json file (which is read by the BGE as a dictionary) as a property, so that we can access it from anywhere else at any time.
(Here’s something cool I discovered about Blender object properties: You can save them as ANYTHING. Lists, dictionaries, EVEN OBJECTS THEMSELVES. Try it, it’s REALLY useful!)
So, put an “itemlist” property on whichever object you’d be accessing for this kind of thing (I like to have a central empty called “game_info” to store stuff like this), and in your startup script, simply save the dict into the property like so:
obj_info = bge.logic.getCurrentScene().objects['game_info']
obj_info['itemlist'] = dict_itemlist
Now, you can access this from any other script, anywhere else in your game. Here’s a little example for equipping the player:
dict_itemlist = obj_info['itemlist']
player['currentWeapon'] = dict_itemlist['weapons']['magic_sword']
And WHA-BAM, your sword is equipped. There’s obviously a lot more to do in order to create things like UI and functional equipping methods, but I hope this helps somewhat.