-
Hello! been messing around with koota for a few days now and have been really enjoying it, however i cant seem to figure out how to add a relationship with non-default value. This is what i've tried const gold = ecs.world.spawn();
const chest = ecs.world.spawn();
const Contains = relation({ store: { amount: 0 } });
chest.add(Contains(gold),{ amount: 10 }); //Cannot read properties of undefined (reading 'createStore')
chest.set(Contains(gold),{ amount: 10 }); //TypeError: Cannot read properties of undefined (reading 'store')
chest.set(Contains(gold,{ amount: 10 })); //Cannot read properties of undefined (reading 'store')
chest.add(Contains(gold,{ amount: 10 })); //does not error out, but...
console.log(chest.get(Contains(gold)))//{amount:0} Any help is appreciated, thanks :) |
Beta Was this translation helpful? Give feedback.
Answered by
r04423
May 18, 2025
Replies: 2 comments 1 reply
-
This should do it, I believe const chest = ecs.world.spawn();
const gold = ecs.world.spawn();
const Contains = relation({ store: { amount: 0 } });
// Option 1: add and set
chest.add(Contains(gold));
chest.set(Contains(gold), { amount: 5 });
// Option 2: add shortcut
chest.add(Contains(gold)({ amount: 5 })); |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
n4t4l
-
Glad you got an answer. I agree we can improve the ergonomics here and for relations in general. I started a discussion to collect ideas: #114 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This should do it, I believe