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: Table Not Working

Previous Thread :: Next Thread 
RoyStanford is not online. RoyStanford
Joined: 21 Oct 2008
Total Posts: 2222
06 Oct 2013 12:44 PM
local newName = {
b1Down = false,
ammoInClip = 0,
maxInClip = 0,
ammoOutClip = 0,
lastEventType = nil,
}

Why does print(#newName) return 0?
Also the for n,v in pairs(newName do doesn't seem to be working. Any ideas?
Report Abuse
lucas668 is not online. lucas668
Joined: 18 Jun 2008
Total Posts: 6183
06 Oct 2013 12:59 PM
print(#newName) will return 0 because there are 0 numbered indices - Example

tab = {false, 0, 0, 0, nil} print(#tab)

will return 4 (nil doesn't count because its nil and considered empty) because the indices for those items are created by their order in the table and aren't represented by a string or object index (By the way, 'index' plural is 'indices'). You indexed your values as strings instead of numbers so they are not counted ("b1Down" is the string index for "false", example newName["b1Down"] and newName.b1Down are accessing the same value, but newName[1] would be nil).


pairs(newName) would work, although ipairs(newName) would not. iPairs goes through numbered indices and ignores strings, pairs does not.
Report Abuse
Iterations is not online. Iterations
Joined: 22 Jul 2013
Total Posts: 751
06 Oct 2013 01:08 PM
function tLen(tab)
local x=0;
for i,v in pairs(tab)do
x=x+1;
end
return x;
end

print(tLen(newName));
Report Abuse
RoyStanford is not online. RoyStanford
Joined: 21 Oct 2008
Total Posts: 2222
06 Oct 2013 01:18 PM
local tbl = {
primary = nil,
secondary = nil,
}

for n,v in pairs(tbl) do
print(n,v)
end

this prints nothing :(
Report Abuse
Iterations is not online. Iterations
Joined: 22 Jul 2013
Total Posts: 751
06 Oct 2013 01:33 PM
Because they're nil...
Report Abuse
RoyStanford is not online. RoyStanford
Joined: 21 Oct 2008
Total Posts: 2222
06 Oct 2013 01:42 PM
Makes sense :3
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