aboutsummaryrefslogtreecommitdiff
path: root/tutorials/tut030_inventories.md
diff options
context:
space:
mode:
authorAlexander Pickering <alexandermpickering@gmail.com>2019-05-04 15:52:00 -0400
committerAlexander Pickering <alexandermpickering@gmail.com>2019-05-04 15:52:00 -0400
commitfaa8312074e6ea8a96efd70d6188ef592f81e579 (patch)
tree5b2d47dae86a2f5fd96c379a20163177b44e20ea /tutorials/tut030_inventories.md
parent984401ce1f84581786f9e3241caf96bda718940b (diff)
downloadartery-faa8312074e6ea8a96efd70d6188ef592f81e579.tar.gz
artery-faa8312074e6ea8a96efd70d6188ef592f81e579.tar.bz2
artery-faa8312074e6ea8a96efd70d6188ef592f81e579.zip
Updated tutorials
Various fixes and updates for the tutorials
Diffstat (limited to 'tutorials/tut030_inventories.md')
-rw-r--r--tutorials/tut030_inventories.md22
1 files changed, 17 insertions, 5 deletions
diff --git a/tutorials/tut030_inventories.md b/tutorials/tut030_inventories.md
index 41fb293..1ac45a0 100644
--- a/tutorials/tut030_inventories.md
+++ b/tutorials/tut030_inventories.md
@@ -6,23 +6,34 @@ Many gamemode bases try to build an inventory system into the gamemode, leaving
In this tutorial, we'll build a simple rougelike inventory, where we expect items to have a "weight", and we can carry as many items as we want, as long as we don't exceed our "max weight".
-Inventories and items in Artery are just tables, as per usual in lua. They have a few required fields each. On the left, under "Classes" (all the way at the bottom!), open invtbl and itemtbl in new tabs.
+Inventories and items in Artery are just tables, as per usual in Lua. They have a few required fields each. On the left, under "Classes" (all the way at the bottom!), open invtbl and itemtbl in new tabs. invtbl contains a list of methods every inventory has, and itemtbl contains a list of methods every item has.
## A simple inventory
You can see all the fields needed for an inventory, so let's get started. Recall that
function tbl:func_name(one)
+ print(self.Name)
...
end
is the same as
function tbl.func_name(self,one)
+ print(self.Name)
...
end
-lua will automatically create the variable "self" in the first example
+Note the period `tbl.func_name` versus the colon `tbl:func_name`.
+Lua will automatically create the variable "self" in the first example
+
+and that the function calls:
+
+ sometable:dothing("blah")
+
+is the same as
+
+ sometable.dothing(sometable,"blah")
garrysmod/addons/artery_rougelite/data/artery/global/rougeinv.lua
@@ -73,7 +84,7 @@ garrysmod/addons/artery_rougelite/data/artery/global/rougeinv.lua
self.weight = self.weight + item.weight
end
- --This one is a bit complicated
+ --This one is a bit complicated, check if we have an item.
--ptr can be either a string, or a function that takes 1 argument,
-- and returns true when given an object we should return.
--this function returns a POSITION that can be given back to get, remove, ect.
@@ -124,8 +135,9 @@ garrysmod/addons/artery_rougelite/data/artery/global/rougeinv.lua
--Re-creates this inventory from the data created by Serialize()
function inv:DeSerialize(data)
- local self_copy = table.Copy(self)
local json = util.JSONToTable(data)
+ self.items = {}
+ self.weight = 0
for k,v in pairs(json) do
local item_name = v[1]
local item_data = v[2]
@@ -135,7 +147,7 @@ garrysmod/addons/artery_rougelite/data/artery/global/rougeinv.lua
for k,v in pair(self_copy.items) do
self_copy.weight = self_copy.weight + v.weight
end
- return self_copy
+ return self
end
--Don't forget to register it with the gamemode!