Answered by
8 years ago Edited 8 years ago
First of all, if p~=nil then
is checking if p actually exists, the ~=
part means "does not equal." The next part ch=p.Backpack:getChildren()
puts all the children of Backpack into a table. With all the children in a table you can iterate over each entry and check the child for specific properties, names, etc... This is where the "for" function comes in. it's saying that for as long as there is an entry in ch (one of the children) then run the function, and increment "i" (which is a variable initialized as 1) by 1. For every time it encounters another entry in the ch table it's going to check a few things, first it's going to check if the name of the object at table entry "i" does not equal "Examine".
How Tables Work:
Tables are laid out as a bunch of entries one after the other, where each entry is the position (or number) of the last entry plus 1 by default. For example if the ch table had four entries in it, it would look like this: ch{"entry 1", "entry 2", entry 3", entry 4"}
. so if we wanted to find what's at entry 3 we would check ch[3]
. This is where "i" comes in, since we increment "i" every time we run the function it's always going to check ch at a new entry. Then, for every entry, it runs the if statement checking if the object name does not equal all the various names laid out above, and if it doesn't equal any of them, then remove the object.