Skip to content

How to add relationship with value? #113

Answered by r04423
n4t4l asked this question in Q&A
Discussion options

You must be logged in to vote

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 }));

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@n4t4l
Comment options

Answer selected by n4t4l
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants