generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: How do you check if a table is empty

Previous Thread :: Next Thread 
JigglingJack is not online. JigglingJack
Joined: 25 Mar 2014
Total Posts: 11263
08 Apr 2014 12:30 AM
if table[1] == nil then ?

i'm asian
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
08 Apr 2014 12:32 AM
You can't really, the only _true_ way is:

local stuff = #table
for index, value in next, table do
stuff = stuff + 1
end
Report Abuse
robotmega is not online. robotmega
Joined: 16 May 2009
Total Posts: 14084
08 Apr 2014 01:44 AM
ozzypig knows how
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
08 Apr 2014 04:30 AM
Table = {}

if #Table == 0 then
--Code
end



Your telling me this wouldn't work?
Report Abuse
M39a9am3R is not online. M39a9am3R
Joined: 10 Nov 2012
Total Posts: 1933
08 Apr 2014 04:36 AM
I've used war's method before, it works.
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
08 Apr 2014 12:40 PM
I thought so...
Report Abuse
wazap is not online. wazap
Joined: 29 Jun 2007
Total Posts: 23234
08 Apr 2014 12:41 PM
Nope.

Test this

table = {Pandas = 12}

print(#table)
Report Abuse
smiley599 is not online. smiley599
Joined: 23 Jan 2010
Total Posts: 21869
08 Apr 2014 12:44 PM
#table is fine.

table[1] is an intersting way, try it!
Report Abuse
wazap is not online. wazap
Joined: 29 Jun 2007
Total Posts: 23234
08 Apr 2014 12:46 PM
@smiley test my code first and then tell me if it works.

And the same thing with table[1]. table[1] could be nil but table[2] might not be.
Report Abuse
makerror is not online. makerror
Joined: 29 Aug 2011
Total Posts: 493
08 Apr 2014 12:48 PM
t = {h,"hello",lol = 90}
print(t[1])
Report Abuse
wazap is not online. wazap
Joined: 29 Jun 2007
Total Posts: 23234
08 Apr 2014 12:49 PM
And before anyone tries this this will not work either

if table == {} then

^That's like saying

if workspace.Part == Instance.new("Part") then
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
08 Apr 2014 12:51 PM
Mine works fine...
Report Abuse
wazap is not online. wazap
Joined: 29 Jun 2007
Total Posts: 23234
08 Apr 2014 12:53 PM
@war

> table = {Panda = 12} print(#table)
0
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
08 Apr 2014 01:02 PM
That is because your putting in a nil value...

How do you cycle through nil values of a table?
Report Abuse
wazap is not online. wazap
Joined: 29 Jun 2007
Total Posts: 23234
08 Apr 2014 01:07 PM
Its not a nil value. This is what I'm doing

table = {Panda = 12} is equivalent to

table["Panda"] = 12


or
table = {["Panda"] = 12}

Also, if you think this is the case, try this

table = {}
table[2] = 12
print(#table)
> 0

And you use for i, v in pairs(table) do
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
08 Apr 2014 01:26 PM
Sorry. Never noticed you were assigning a variable. I'm dumb.


If that is the case, you were using a dictionary, I don't have a clue how to figure out how many variables are in a dictionary
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
08 Apr 2014 01:27 PM
Aren't you supposed to use ipairs?
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
08 Apr 2014 06:52 PM
-.-

Just use mine even though mine isn't going to show keys with nil values.
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
08 Apr 2014 06:53 PM
War, a "dictionary" is just a table without all numerical-based keys.
Report Abuse
jonesj627 is not online. jonesj627
Joined: 06 Oct 2010
Total Posts: 1496
08 Apr 2014 06:54 PM
if table == nil then
--code
end
Report Abuse
dogwarrior24 is not online. dogwarrior24
Joined: 10 Nov 2010
Total Posts: 1401
08 Apr 2014 06:55 PM
#table works perfectly, if its 0 then the table is empty.
Report Abuse
wazap is not online. wazap
Joined: 29 Jun 2007
Total Posts: 23234
08 Apr 2014 07:56 PM
@dog try this

table[2] = "LOL"
print(#table)
gg.
Report Abuse
TaaRt is not online. TaaRt
Joined: 26 Apr 2009
Total Posts: 5039
08 Apr 2014 08:00 PM
Even concat fails there, though would you often assign something to position 1 without assigning to 0?
Report Abuse
JigglingJack is not online. JigglingJack
Joined: 25 Mar 2014
Total Posts: 11263
08 Apr 2014 08:04 PM
I didn't think there was a position 0 in rbx Lua

i'm asian
Report Abuse
TaaRt is not online. TaaRt
Joined: 26 Apr 2009
Total Posts: 5039
08 Apr 2014 08:07 PM
err, my bad
2 and 1 I meant
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image