aboutsummaryrefslogtreecommitdiff
path: root/tutorials/tut040_items.md
blob: 954f9cdcf9a791f45a99237c6b8387d81624b5e6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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!