swordandquill

Load Items into Database

Oct 23rd, 2024
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
GDScript 0.55 KB | Source Code | 0 0
  1. var folder_path: String # something like "res://data/resources/items/"
  2. var item_database: Array
  3.  
  4. func _load_all_items():
  5.     var dir = DirAccess.open(_path)
  6.     if dir:
  7.         dir.list_dir_begin()
  8.         var file_name = dir.get_next()
  9.        
  10.         while file_name != "":
  11.             if dir.current_is_dir():
  12.                 print("Found directory: " + file_name)
  13.             else:
  14.                 print("Found file: " + file_name)
  15.                 var item  = load(folder_path + file_name)
  16.                 item_database.append(item)
  17.  
  18.             file_name = dir.get_next()
  19.     else:
  20.         print("An error occurred when trying to access the path.")
Advertisement
Add Comment
Please, Sign In to add comment