Answers for "gdscript dictionary basic example"

0

gdscript dictionary basic example

extends Node

func _ready():
	var dict = {"name":"generalistprogrammer"}
	var dictdeep = {"name":"generalistprogrammer", "skills":{"backend":"yes", "frontend":"yes"}}
	
	dict.clear()
	print("After calling clear() " + String(dict))
	
	dict = {"name":"generalistprogrammer"}
	
	var duplicateddict = dict.duplicate()
	print("Printing duplicated dict: " + String(duplicateddict))
	
	var duplicateddictdeep = dictdeep.duplicate(true)
	print("Printing duplicated dictdeep: " + String(duplicateddictdeep))
	
	var duplicateddictnotdeep = dictdeep.duplicate()
	print("Printing duplicated dictdeep not deep: " + String(duplicateddictnotdeep))
	
	var emptydict = {}
	
	print("Printing emptydict: " + String(emptydict.empty()))
	print("Printing not empty dict: " + String(dict.empty()))
	
	var result = dictdeep.erase("name")
	print("Printing key erase the resul was: "+ String(result) + " and the end dict is : "+ String(dictdeep))
	
	print("Printing a get: "+ dict.get("name"))

	print("Printing a has example: "+ String(dict.has("name")))
	
	var hasall = dictdeep.has_all(["name","skills"])
	print("Printing example of has_all: "+ String(hasall))	
	
	print("Printing example of keys: " + String(dict.keys()))
	
	print("Printing example of size: " + String(dict.size()))
	
	print("Printing example of values: " + String(dict.values()))
	
	var dict1 = {"name":"GP"}
	var dict2 = {"name":"GP"}
	print("Printing example of regular comparison: "+ String(dict1 == dict2))
	print("Printing example of hash comparison: "+ String(dict1.hash() == dict2.hash()))
Posted by: Guest on June-25-2021

Browse Popular Code Answers by Language