E
E
Ensiouel2018-07-20 11:00:07
Lua
Ensiouel, 2018-07-20 11:00:07

Why can't I get the number of elements in an array?

I'm an amateur in this matter, I ask you not to throw slippers, but a problem arose
. I created a certain "class" to which I add elements, and when I try to find out the number of elements that are present in the array, I write 0 through "#"

class = {}
function class:new()

  local class = {}
    class.layer = {}

  function class:add(object)
   		for key, value in pairs(object) do
        	self.layer[key] = value
   		end
  end

  function class:returnCount()
    return #self.layer --Вернет 0
  end

  setmetatable(class, self)
  self.__index = self; return class
end

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis, 2018-07-20
@notwrite

# can't count key-value pairs.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question