From 83af51534bf16bf048aea1cd3b74a0308ed9dd71 Mon Sep 17 00:00:00 2001 From: Alexander Pickering Date: Sun, 26 Nov 2017 21:07:54 -0500 Subject: Started work on writing tutorials Wrote tutorials for * Setup * Addon structure * Inventories * Items --- tutorials/tut040_items.md | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 tutorials/tut040_items.md (limited to 'tutorials/tut040_items.md') diff --git a/tutorials/tut040_items.md b/tutorials/tut040_items.md new file mode 100644 index 0000000..954f9cd --- /dev/null +++ b/tutorials/tut040_items.md @@ -0,0 +1,25 @@ +# Tut 0x040 + +## Items + +Items are a lot like inventories, but much simpler. Let's make one! + + local item_registry = nrequire("item.lua") + local item = {} + + item.Name = "My first item" + + function item:Serialize() + return "" + end + + --Recall that we said in @{tut030_inventories.md} we said items that work in our inventory will have a .weight field + item.weight = 20 + + function item:DeSerialize() + return table.Copy(self) + end + + item_registry.RegisterItem(item) + +That's it! We're Done! Note you can use the same trick in DeSerialize() as in @{tut031_metatables.md}. You can now load in to the game and use `artery_printitems` to show a list of items, and see "My first item" as one of them! -- cgit v1.2.3-70-g09d2