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: What's the difference?

Previous Thread :: Next Thread 
systematicaddict is not online. systematicaddict
Joined: 13 Jul 2012
Total Posts: 4188
30 Jul 2017 12:06 PM
Why can I do

for i,v in pairs{...} do

but not

for i,v in next{...} do

... is for variadic functions, I'm calling it in a variadic function
Report Abuse
systematicaddict is not online. systematicaddict
Joined: 13 Jul 2012
Total Posts: 4188
30 Jul 2017 01:38 PM
b
Report Abuse
systematicaddict is not online. systematicaddict
Joined: 13 Jul 2012
Total Posts: 4188
30 Jul 2017 02:37 PM
Can anyone answer this? I thought pairs just used the next function, so wouldn't it be the same? I'm a lil confused
Report Abuse
Pinkerten is not online. Pinkerten
Joined: 03 Aug 2014
Total Posts: 840
30 Jul 2017 02:44 PM
Don't use next.
Report Abuse
systematicaddict is not online. systematicaddict
Joined: 13 Jul 2012
Total Posts: 4188
30 Jul 2017 02:48 PM
Can you explain why it errors, though?

14:48:02.765 - Workspace.Script:2: attempt to call a number value
Report Abuse
Pinkerten is not online. Pinkerten
Joined: 03 Aug 2014
Total Posts: 840
30 Jul 2017 02:51 PM
Honestly, I can't.
I've used it before and met people who swear to it, but I know many more people far more intelligent than me who use in pairs.
Report Abuse
Soybeen is not online. Soybeen
Joined: 17 Feb 2010
Total Posts: 21462
30 Jul 2017 02:57 PM
Ignore Pink, he doesn't know what he's talking about It heavily depends on what you're trying to do. ipairs iterates over only integer keys, so if you have a mixed dictionary/array like this... table = {"thing1","thing2","thing3",["something else"] = true, ["another defined thing"] = "hello"} for i,v in ipairs(table) do print(i,v) end >1 thing1 >2 thing2 >3 thing3 It would totally ignore the definitions Pairs and Next are basically the same. Pairs calls Next, it's just there so that you can use the parenthesis around your table if that's what you're into. It will print both integer and noninteger keys. Keep in mind noninteger keys have no order. for i,v in next,table do print(i,v) end OR for i,v in pairs(table) do print(i,v) end will both print the same thing: >1 thing1 >2 thing2 >3 thing3 >something else true >another defined thing hello Answering scripting questions ## ####### ###########################
Report Abuse
Soybeen is not online. Soybeen
Joined: 17 Feb 2010
Total Posts: 21462
30 Jul 2017 02:58 PM
Ignore Pink, he doesn't know what he's talking about

It heavily depends on what you're trying to do.

ipairs iterates over only integer keys, so if you have a mixed dictionary/array like this...

table = {"thing1","thing2","thing3",["something else"] = true, ["another defined thing"] = "hello"}

for i,v in ipairs(table) do
print(i,v)
end
>1 thing1
>2 thing2
>3 thing3

It would totally ignore the definitions

Pairs and Next are basically the same. Pairs calls Next, it's just there so that you can use the parenthesis around your table if that's what you're into. It will print both integer and noninteger keys. Keep in mind noninteger keys have no order.

for i,v in next,table do
print(i,v)
end

OR

for i,v in pairs(table) do
print(i,v)
end

will both print the same thing:

>1 thing1
>2 thing2
>3 thing3
>something else true
>another defined thing hello

Report Abuse
Pinkerten is not online. Pinkerten
Joined: 03 Aug 2014
Total Posts: 840
30 Jul 2017 03:02 PM
^I forgot to use a comma. for i in next,{"Corn"} do print(i) end # ## ##### still stands. Don't use next.
Report Abuse
systematicaddict is not online. systematicaddict
Joined: 13 Jul 2012
Total Posts: 4188
30 Jul 2017 03:03 PM
Ah, I understand now

so doing

for i,v in next,{...} do

works fine

Thanks for clearing that up
Report Abuse
Soybeen is not online. Soybeen
Joined: 17 Feb 2010
Total Posts: 21462
30 Jul 2017 03:04 PM
There is NO problem with next
Pairs calls next. Don't mislead him.
Report Abuse
Pinkerten is not online. Pinkerten
Joined: 03 Aug 2014
Total Posts: 840
30 Jul 2017 03:06 PM
^ I never said there was a problem did I?
And there is. It looks bad. Thats it.
There is no other reason to use pairs over next other than next looks ugly.
So I use pairs, and I agree with others that it is much more readible.
Report Abuse
Soybeen is not online. Soybeen
Joined: 17 Feb 2010
Total Posts: 21462
30 Jul 2017 03:08 PM
It doesn't look bad, are you dense?
If you have a problem with reading the difference, you got a bone in the middle of your head.

How can you stand adding those args to For?
for i,v in -- you should have an issue with this if you have an issue with in next,thing do
Report Abuse
systematicaddict is not online. systematicaddict
Joined: 13 Jul 2012
Total Posts: 4188
30 Jul 2017 03:08 PM
Yeah, that's why I asked because I knew that pairs called next, I was just confused on why it wasn't working the same way, but it totally makes sense now.
Report Abuse
Soybeen is not online. Soybeen
Joined: 17 Feb 2010
Total Posts: 21462
30 Jul 2017 03:10 PM
Yeah, you can use both, it's a matter of preference.

To say "don't use next over pairs", that's horribly unhelpful and makes it seem like next is inferior to pairs.

It is totally a choice.
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