Advertisement
gdcoder

argv to array

Aug 25th, 2021
506
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. extends Node2D
  2.  
  3. const MIN_WIDTH = 10
  4.  
  5. func _ready():
  6.     test([])
  7.     test([2])
  8.     test([2, 3])
  9.  
  10. func get_grid(argv: Array):
  11.     var width = argv.pop_front() # get null or value
  12.     var height = argv.pop_front() # get null or value
  13.     if width == null:
  14.         width = MIN_WIDTH
  15.     if height == null:
  16.         height = width
  17.     var grid = []
  18.     grid.resize(height)
  19.     var row = []
  20.     row.resize(width)
  21.     row = PoolIntArray(row) # Generate a row of integer zeros
  22.     for n in height:
  23.         grid[n] = Array(row) # Cast to array
  24.     return grid
  25.  
  26. func test(argv):
  27.     var grid = get_grid(argv)
  28.     print("size: ", Vector2(grid.size(), grid[0][0].size()))
  29.     print("row: ", grid[0][0])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement