Sending and retrieving information to and from a single script

Godot Version



In this program, the user can create a custom pattern, that pattern then gets loaded into a sprite, and when that new sprite is clicked, it loads the saved pattern. As of now, it is able to load the last drawn pattern, but I’d like it to apply a new pattern to each sprite created. I’ve tried storing the patterns into an array and gathering them from there, and tried using 2 separate signals to send and retrieve the patterns. I feel the issue has to do with the script being applied to the sprite, but I’m unsure. If there’s any way this can be optimized, or solved, I’d appreciate the help. Thank you!

extends TileMap

func _create_Template(): # grab information from the users drawn template and save it as a new template
	var sprite : Sprite2D = # creates new sprite to store the pattern info
	for x in 23:
		for y in 23:
			scanArray.append(Vector2i(posX + x, posY + y))
	pattern = get_pattern(0, scanArray)
	sprite_script = load("res://") # load script that places pattern when sprite is clicked

	sprite.texture = load("res://Tiles/blank.png") # placeholder, need to find a way to upload picture of drawn pattern
	sprite.scale = Vector2(0.15, 0.15)
	sprite.position = Vector2i(newTempX, 200)
	newTempX = newTempX + 100

#func _placecustom_Template(newPat):
	#set_pattern(0, Vector2i(18, 6), newPat)
func _placecustom_Template(): # place custom template	
		set_pattern(0, Vector2i(18, 6), pattern)

extends Sprite2D

#var pattern : TileMapPattern

#func _ready():
	#Global.connect("getPattern", _get_Pattern)
#func _get_Pattern(pat):
	#pattern = pat

func _input(event):
	if Input.is_action_just_pressed("mb_left"):
		if get_rect().has_point(to_local(event.position)):
			var mat = "temp"