minetest / minetest_docs

Minetest Engine documentation (Work in progress. Meanwhile, please refer to lua_api.txt and dev.minetest.net)
Other
22 stars 13 forks source link

Document ItemStack returning functions #18

Open appgurueu opened 2 years ago

appgurueu commented 2 years ago

on_use etc. Include a note that prevents people from making the common mistake of trying to modify the inventory before/instead of returning the itemstack they want to be set.

appgurueu commented 2 years ago

The confusion here is likely to stem from the fact that ItemStack is a mutable reference type, yet all functions & callbacks using ItemStacks pass them "by value", copying them (constrast this with e.g. vectors which are mutable but only provide methods that return copies, thus making it apparent that you have to feed the vector back in using some setter). I wonder whether such a note would suit the ItemStack doc well?