Search
 
SCRIPT & CODE EXAMPLE
 

GDSCRIPT

GDScript dictionary

extends Node2D

# Declare an empty dictionary object
var game = {}

func _ready():
	# Initialize a player dictionary
	var player = {
		"name": "Thor",
		"inventory": ["sword", "shield", "map"],
		"location": "Castellion",
		"energy": 67
	}
	
	if game.empty():
		# Add data to the game dictionary
		game["player"] = player
		game["score"] = 0
		game["dummy"] = null
	
	if game.has("dummy"):
		game.erase("dummy")
	
	print(game.get("dummy", "Key not found!"))
	
	if game.has_all(["player", "score"]):
		print(game["player"]["name"])
	
	player["energy"] += 1
	
	print(game.keys().size())
	print(game.size())
	print(player.values()[0])
	
	# Alternative way to initialize a dictionary
	var d = {
		a = {
			a1 = {
				a11 = 1, a12 = 2
			},
			a2 = 3
		},
		b = 1
	}
	
	# Make copies of the dictionary
	var deep_copy = d.duplicate(true)
	var shallow_copy = d.duplicate()
	print(deep_copy)
	# I expected the shallow copy to be truncated
	print(shallow_copy)
Comment

PREVIOUS NEXT
Code Example
Gdscript :: godot saving enum names in variable 
Clojure :: what is var in Clojure 
Clojure :: how to make a directory in clojure 
Abap :: abap shortcut comments 
Abap :: sap checkbox abap 
Cobol :: python pygments install 
Assembly :: latex image textwidth 
Assembly :: 64 bit assembly Hello world 
Assembly :: how to check if chat is nsfw discord.py 
Assembly :: Z language latex 
Assembly :: dokuwiki redirect 
Assembly :: pytorch list gpus 
Javascript :: jquery vslidation remove spaces from input 
Javascript :: window load jquery 
Javascript :: clean gradle react android 
Javascript :: toggle text jquery 
Javascript :: JavaScript that executes after page load 
Javascript :: javascript void(0) href 
Javascript :: jquery reload page 
Javascript :: java script converting text to slug 
Javascript :: change src of iframe jquery 
Javascript :: change input to required jquery 
Javascript :: return current date in javascript 
Javascript :: javascript random color generator 
Javascript :: sleep for 1 second 
Javascript :: fetch json post 
Javascript :: exclude node_modules from tree command 
Javascript :: mongoose nestjs installation 
Javascript :: generating component in angular without spec file 
Javascript :: number with commas js 
ADD CONTENT
Topic
Content
Source link
Name
5+4 =