IDs in addition to tags #371
oaklandgit
started this conversation in
Ideas
Replies: 2 comments 1 reply
-
hmmm, yeah, something like id comp, like a tag but unique |
Beta Was this translation helpful? Give feedback.
0 replies
-
Sounds like a sugar for const nameRegistry: Record<string, GameObj> = {};
function name(name: string) {
return {
id: "name",
name: name,
add() {
if (nameRegistry[name]) {
throw new Error(`Name already exists: ${name}`)
}
nameRegistry[name] = this;
},
destroy() {
delete nameRegistry[name];
},
}
}
function getUnique(name: string) {
return nameRegistry[name];
}
add([
sprite("froggy"),
name("player"),
]) One thing is I think |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I know that a class of game objects can be referenced by tag, as in:
and that a single game object can be referenced via variable, as in:
but letting Kaboom manage unique objects would be useful, and likely easier for newbies like:
which could later be referenced as:
Beta Was this translation helpful? Give feedback.
All reactions