Godot Version
4.2.1
Question
I am making a game that consists of a number of Point Nodes.
extends Node2D
class_name Point
@export var industry:Industry
@export var items:Dictionary
var pops:float
Each Point has an items Dictionary where the key is an Item, and the value is a float representing how much of that item is at that Point.
In the editor, in point.tscn it set the Items dictionary to be
key: Resource(“res://Assets/Items/Food.tres”)
value: 0
Also each Point has an Industry
extends Resource
class_name Industry
@export var industry_name:String
@export var output_per_pop:Dictionary
The Industry Farming.tres has the output_per_pop set to
" key: Resource(“res://Assets/Items/Food.tres”)
value: 2 "
in the editor
The desired behavior of the program is to update each Point with increased items. Each Point should have its own unique amount of food stored in the items Dictionary.
However, my problem is that this is not happening! Instead updating the Items[Food] value of one Point updates the Items[Food] value of every Point!
The _process() of Point looks like this
func _process(delta):
for item in industry.output_per_pop:
var new_items:float = delta * industry.output_per_pop[item] * pops
items[item] += new_items
pass
When I put a breakpoint on “pass” I can see that across all my Point Nodes the key of “items” is an Object with the same Object id. Also the value is the same for all of them. Increasing the Items[Food] value of one Point Node changes the value for all point nodes.
It seems like the “items” dictionary of all Point Nodes all point to the same location in memory?
Why does this happen even though other variables like “pops” are unique between Point Nodes?
How do I make it so that the value of each items[Food] is different across my different point nodes?