*SOLVED* A really-really small question.

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
User avatar
ffive
Prole
Posts: 16
Joined: Wed Oct 22, 2014 3:22 pm

*SOLVED* A really-really small question.

Post by ffive »

Hi.

Um, can't find answer anywhere else.. :(
What does number sign (#) operator do in Lua?
Last edited by ffive on Tue Nov 18, 2014 2:13 pm, edited 2 times in total.
.·˙·.·˙·.·˙·.·˙·.·˙·.·˙·.·˙·.·˙·.·˙·.·˙·.·˙·.·˙·.·˙·.·˙·.·˙·.·˙·.·˙·.·˙·.·˙·.·˙
User avatar
Doctory
Party member
Posts: 441
Joined: Fri Dec 27, 2013 4:53 pm

Re: A really-really small question.

Post by Doctory »

gives you the size of a table.
for ex, a table has 3 items, table[1], table[2], and table[3]
if you use #table, it will return 3, because thats how much items the table has
User avatar
ffive
Prole
Posts: 16
Joined: Wed Oct 22, 2014 3:22 pm

Re: A really-really small question.

Post by ffive »

Huge thanks!
.·˙·.·˙·.·˙·.·˙·.·˙·.·˙·.·˙·.·˙·.·˙·.·˙·.·˙·.·˙·.·˙·.·˙·.·˙·.·˙·.·˙·.·˙·.·˙·.·˙
User avatar
Doctory
Party member
Posts: 441
Joined: Fri Dec 27, 2013 4:53 pm

Re: *SOLVED* A really-really small question.

Post by Doctory »

no problem
User avatar
zorg
Party member
Posts: 3470
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: *SOLVED* A really-really small question.

Post by zorg »

Note that it only works for the numeric part of a table (starting from 1, going until the next index is nil), so if you have gaps, then it won't report the "true" size of the table... and it doesn't count any other key either.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
User avatar
Ref
Party member
Posts: 702
Joined: Wed May 02, 2012 11:05 pm

Re: *SOLVED* A really-really small question.

Post by Ref »

Let's not forget strings.
str = 'This is a string'
#str returns length of str - 16.
User avatar
Doctory
Party member
Posts: 441
Joined: Fri Dec 27, 2013 4:53 pm

Re: *SOLVED* A really-really small question.

Post by Doctory »

Ref wrote:Let's not forget strings.
str = 'This is a string'
#str returns length of str - 16.
ah, cool
for up to now i've been using string.len()
thanks for this info
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 5 guests