How can I add scripts to individual tiles in a Tilemap2D?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Johnnyfantastic6

I am trying to make a version of carykh’s ‘evolvio’ in Godot engine.
I need to add params that change over time or when interacted with

how can I do this?

example for the script:

var max_food = 10
var food = max_food
var fertility = 10
 
func _procces(delta):
    food += fertility * delta
    clamp(food, 0, max_food)
:bust_in_silhouette: Reply From: clemens.tolboom

You need to have a world state.

I created a Node2D scene with a TileSet with a TileSet image. Mine has 12 tiles.

I set one tile every _process randomly

extends Node2D

onready var tiles:TileMap = $TileMap

var world_width:int = 100
var world_height:int = 100

var world_state:PoolIntArray

func _ready():
	world_state = PoolIntArray()
	world_state.resize(world_width * world_height)

func _process(delta):
	# Select a random cell
	var x:int = randi() % world_width
	var y:int = randi() % world_height
	var food:int = randi() % 12
	# Change world state
	world_state[x + y * world_height] = food

	tiles.set_cell(x, y, world_state[x + y * world_height])

Hope this answers your question.