How to get number of objects/shapes in scene?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
badfitz66
Prole
Posts: 29
Joined: Sat Jun 07, 2014 10:30 pm

How to get number of objects/shapes in scene?

Post by badfitz66 »

I am editing a code, with two shapes in the scene (the circle and the ground), they're each in a table

is there a way I can get the amount of objects inside the table?
What a wonderful caricature of intimacy
User avatar
Ranguna259
Party member
Posts: 911
Joined: Tue Jun 18, 2013 10:58 pm
Location: I'm right next to you

Re: How to get number of objects/shapes in scene?

Post by Ranguna259 »

Code: Select all

#table
Did you search the web before posting ?
LoveDebug- A library that will help you debug your game with an on-screen fully interactive lua console, you can even do code hotswapping :D

Check out my twitter.
User avatar
HugoBDesigner
Party member
Posts: 403
Joined: Mon Feb 24, 2014 6:54 pm
Location: Above the Pocket Dimension
Contact:

Re: How to get number of objects/shapes in scene?

Post by HugoBDesigner »

If you have simply an array table, you can just use:

Code: Select all

amount = #myTable
But if you have a table with multiple different items in it (for example "table.x", "table['n']" and others), you can use this function I made (which is quite simple, so someone else probably already made it before):

Code: Select all

amount = table.size(myTable)

Code: Select all

function table.size(t)
   local s = 0
   for i, v in pairs(t) do
      s = s + 1
   end
   return s
end
@HugoBDesigner - Twitter
HugoBDesigner - Blog
Post Reply

Who is online

Users browsing this forum: slime and 3 guests