Components from Luau: AddComponent, GetComponent, GetComponents, Destroy (#75) #83
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
crowmaki/cinnabar#83
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Parent
#75
What to build
Scripts compose GameObjects at runtime.
go:AddComponent(Mover)attaches a Component, runsAwake, and returns the instance.go:GetComponent(Mover)andself:GetComponent(Mover)return the first Component of that class on the GameObject ornil;go:GetComponents(Mover)returns every one. Both accept a class table or a Schema name string, sogo:GetComponent("cinnabar.rigidbody")finds an Odin-registered Component. A Component that is not Script-defined comes back as a generic userdata withgameObject,IsAlive,Destroyand no field access.Destroy(component)andcomponent:Destroy()queue removal for the next Structural Flush.A GameObject or Component created inside
Updatereceives its firstUpdateon the next frame: it lies beyond the count captured at the start of that class's walk.Acceptance criteria
go:AddComponent(Mover)returns an instance whoseAwakehas already run, and Odin sees the Component viagameobject_component_countGetComponentreturns the first instance of the class ornil;GetComponentsreturns all of them in on-object orderGetComponentby Schema name string finds an Odin-registered Component and returns a generic userdata; reading a field on it raises an errorDestroy(component)andcomponent:Destroy()leave the Component alive until the next Structural Flush;component_is_aliveis false after itgo:Destroy()from insideUpdatecompletes: every instance alive at the start of the frame still updates that frame, and the destroyed set is gone after the flushUpdatereceives noUpdatethat frame and its firstStartandUpdatethe nextGetComponentcalls for the same Component in one frame compare equal with==Blocked by