Pool System
Overview
Pools are ordered collections of values or entity instances in Morphyn.
Declaration
entity World {
has enemies: pool[1, 2, 3]
has items: pool["sword", "shield"]
has positions: pool[0.0, 10.5, 20.3]
has empty: pool[]
}
Pool Commands
Adding Elements
add — append to end (or spawn entity by name)
emit enemies.add("Enemy") # clones Enemy entity, fires its init
emit items.add("bow")
push — add to front
emit items.push("new_item")
insert — insert at position (1-based index)
emit items.insert(2, "middle_item")
Removing Elements
remove — remove by value
emit enemies.remove(target)
remove_at — remove by index (1-based)
emit enemies.remove_at(3)
pop — remove last element
shift — remove first element
clear — remove all elements
Other Operations
swap — swap two elements (1-based indices)
each — call an event on every element
emit enemies.each("take_damage", 10)
emit items.each("collect", player)
sort — sort elements
reverse — reverse order
contains — check if pool contains a value
emit pool.contains(value) -> result
shuffle — randomize order
Accessing Pools
Get pool size
enemies.count -> num_enemies
Access by index (1-based)
enemies.at[1] -> first_enemy
enemies.at[i] -> current_enemy
Set by index
new_value -> pool.at[index]
Sync result into pool slot
emit MathLib.abs(scores.at[1]) -> scores.at[1]