latticexyz / mud

MUD is a framework for building autonomous worlds
https://mud.dev
MIT License
696 stars 175 forks source link

add IncrBy/DecrBy function for integer #2806

Closed chuwt closed 2 months ago

chuwt commented 2 months ago

Increments or decrements the number stored at key. Very useful for add/sub integer like balance.

holic commented 2 months ago

any reason for a specific function for this when you can just do

Table.setCount(Table.getCount() + 1)
chuwt commented 2 months ago

Yes, but it sometimes becomes duplicate when there are too many keys like:

Table.setCount(key1, key2, key3, Table.getCount(key1, key2, key3) + 1)
# would be good if we support incrBy
Table.incrByCount(key1, key2, key3, 1)

Anyway, just an advanced feature.

holic commented 2 months ago

Appreciate the feedback, but we don't have plans to expand the table API surface area in this way.