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 » Scripters
Home Search
 

Re: Table Question

Previous Thread :: Next Thread 
Sehnsucht is not online. Sehnsucht
Joined: 10 Apr 2011
Total Posts: 990
06 Jan 2015 07:25 PM
tab = {tab2 = {}, tab3 = {}}
print(#tab)
--> 0

tab = {{}, {}}
print(#tab)
--> 2

Why?
Report Abuse
128GB is not online. 128GB
Joined: 17 Apr 2014
Total Posts: 8056
06 Jan 2015 07:27 PM
Because one is a dictionary table and the other isn't


local function getKeys(tab)
local output = {}
for key, _ in next, tab do
table.insert(output, key)
end
return output
end

tab = {tab2 = {}, tab3 = {}}

print(#getKeys(tab))
Report Abuse
QuintinityZero is not online. QuintinityZero
Joined: 01 Oct 2008
Total Posts: 10618
06 Jan 2015 07:28 PM
The # operator only return the number of INTEGER KEYS
Report Abuse
Sehnsucht is not online. Sehnsucht
Joined: 10 Apr 2011
Total Posts: 990
06 Jan 2015 07:28 PM
for key, _ in next, tab do
end

What is the next keyword there, I have never seen that before?
Report Abuse
128GB is not online. 128GB
Joined: 17 Apr 2014
Total Posts: 8056
06 Jan 2015 07:30 PM
Have you seen pairs before?

They are the same thing

Because pairs is actually doing next
Report Abuse
Sehnsucht is not online. Sehnsucht
Joined: 10 Apr 2011
Total Posts: 990
06 Jan 2015 07:31 PM
Yes I normally would use,

for i,v in pairs(tab) do
end
Report Abuse
128GB is not online. 128GB
Joined: 17 Apr 2014
Total Posts: 8056
06 Jan 2015 07:32 PM
Its the same thing, because this is what pairs is doing


local function pairs(tab)
return next, tab
end

local a = {
a = 1;
b = 2;
c = 3;
}

for key, value in pairs(a) do
print(key, value)
end
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
06 Jan 2015 07:35 PM
They aren't the same thing, since pairs uses next. Not to mention next also allows an index to be given to determine the start position.
Report Abuse
128GB is not online. 128GB
Joined: 17 Apr 2014
Total Posts: 8056
06 Jan 2015 07:36 PM
We've been through this before

To me they are the same because they do the same thing

For the same reason

local a = 1
local b = a

Now a and b are the same even though b is using a
Report Abuse
Sehnsucht is not online. Sehnsucht
Joined: 10 Apr 2011
Total Posts: 990
06 Jan 2015 07:37 PM
Thanks for the information I never knew that!
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
06 Jan 2015 07:38 PM
Pairs is a different function than next in memory, the b = a does not apply since it just copies the value instead of stores as a reference.

And 'The # operator only return the number of INTEGER KEYS'
Is not true.
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
06 Jan 2015 07:39 PM
Although yes, pairs does call next but it's not the same thing :)
Report Abuse
128GB is not online. 128GB
Joined: 17 Apr 2014
Total Posts: 8056
06 Jan 2015 07:39 PM
I didn't say they are the same in memory I said they are the same because pairs uses next
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
06 Jan 2015 07:41 PM
Same results would technically be more accurate :)
Report Abuse
iiEssence is not online. iiEssence
Joined: 18 Jun 2014
Total Posts: 3467
06 Jan 2015 07:42 PM
cnt ur a beginner scripter remember

shhh
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • 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