Skip to content

Instantly share code, notes, and snippets.

@RichardEllicott
Last active January 3, 2020 16:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RichardEllicott/92fdc86af74449f5baf6a129aeb14cfc to your computer and use it in GitHub Desktop.
Save RichardEllicott/92fdc86af74449f5baf6a129aeb14cfc to your computer and use it in GitHub Desktop.
extends Node
var inventorys = {} # NEW
func _ready():
LoadDictionary("res://Items/Armor/", "Armor")
LoadDictionary("res://Items/Consumable/", "Consumables")
LoadDictionary("res://Items/Resource/", "Resources")
LoadDictionary("res://Items/Weapons/", "Weapons")
for i in WeaponsInventory:
print("Name: " + WeaponsInventory[i].itemName)
print("Damage: " + String(WeaponsInventory[i].minDamage) + " - " + String(WeaponsInventory[i].maxDamage))
func LoadDictionary(myPath, myItemType):
var new_array = [] # NEW
inventorys[myItemType] = new_array # NEW
var dir = Directory.new()
var id = 0
dir.open(myPath)
dir.list_dir_begin()
while true:
var file = dir.get_next()
# print(myPath + file)
if file == "":
# If there's no other files to worry about, we break...we're done.
break
elif file.ends_with(".tscn"):
print(myItemType + "Inventory")
var itemScene = load(myPath + file).instance()
new_array.append(itemScene) # NEW
id += 1
dir.list_dir_end()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment