Advertisement
freswinn

GDScript: PoolDictionaryArray with predefined keys and values

Mar 3rd, 2023 (edited)
1,862
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # This is a method of creating an array of dictionaries all of which are set to default keys and values,
  2. # which means you can now quickly set up large amounts of data quickly through the inspector
  3.  
  4. tool # will not work if you don't/can't make the script a tool
  5. extends Node # OR WHATEVER
  6.  
  7. export(Array,Dictionary) var pool = [] setget set_pooldict
  8.  
  9. var pool_size = pool.size()
  10. func set_pooldict(pooldictarray : Array):
  11.     var n = pooldictarray.size()
  12.    
  13.     if n > pool_size:
  14.         var pooldict_def = {
  15.             "Predefined String" : "",
  16.             "Predefined Int" : 0,
  17.             "Predefined Float" : 0.0,
  18.             "Predefined Bool" : false
  19.         } #etc; used to have this as a const outside of the function, but this caused weird issues
  20.         pooldictarray[n-1].merge(pooldict_def)
  21.    
  22.     pool_size = n
  23.     pool = pooldictarray
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement