Re: The Inventory
Status: Alpha
Brought to you by:
cwalther
From: Christian W. <cwa...@gm...> - 2012-01-06 09:53:19
|
James C. Wilson wrote: > However, for the future, I'm not aware of what the list index of the > object is, or how to find it. If it's the number that the inventory > table assigns the object Yes, "index" is a common term for the consecutive numbers that the "slots" of a list or array are addressed with. Lua by convention starts counting at 1, most other programming languages start at 0. If you don't know where in the list the object is, then you just search for it. The shortest way of doing that I can find right now is index = table.foreachi(state.inventory, function(i, v) if v == "TVCable" then return i end end) although you can also spell it out as for i = 1, table.getn(state.inventory) do if state.inventory[i] == "TVCable" then index = i break end end > wouldn't that be biased toward the order in which the player picks up > items? Yes, the inventory keeps objects in the order they were picked up. If you don't like that and would rather have them e.g. in a fixed order, you need to change the inventory code. -Christian |