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: Linked List

Previous Thread :: Next Thread 
EvilDonutNoob is not online. EvilDonutNoob
Joined: 26 Jan 2014
Total Posts: 440
16 Nov 2016 11:13 AM
Is this the proper way to do linked lists in Lua

list = {'a',{'b',{'c',{'d'}}}}
Report Abuse
Soybeen is not online. Soybeen
Joined: 17 Feb 2010
Total Posts: 21462
16 Nov 2016 11:17 AM
list = {'a',{'b',{'c',{'d'}}}}

print(list[1])
>a
print(list([2][1])
>b
print(list([2][2][1])
>c
print(list[2][2][2][1])
>d



Report Abuse
Soybeen is not online. Soybeen
Joined: 17 Feb 2010
Total Posts: 21462
16 Nov 2016 11:18 AM
I mean, if you need to store an array within an array within an array within an array, by all means do that.
Otherwise you might find it helpful to leverage ROBLOX's OOP structure and create an actual hierarchy of Value objects to reference.


Report Abuse
TimeTicks is not online. TimeTicks
Joined: 27 Apr 2011
Total Posts: 27115
16 Nov 2016 11:23 AM
if you are talking about 2d arrays then simply

local list = {
a = {
b = {
c = {
d = {
'hi',
},
},
},
},
}

print(list.a.b.c.d) --> hi

or

print(list['a']['b']['c']['d']) --> hi


Report Abuse
chimmihc is not online. chimmihc
Joined: 01 Sep 2014
Total Posts: 17143
16 Nov 2016 11:48 AM
local list = {value = 5}
list = {value = 3, next = list}
list = {value = 8, next = list}
list = {value = 1, next = list}
list = {value = 7, next = list}

print(list.value)
print(list.next.value)
print(list.next.next.value)
print(list.next.next.next.value)
print(list.next.next.next.next.value)


Report Abuse
EvilDonutNoob is not online. EvilDonutNoob
Joined: 26 Jan 2014
Total Posts: 440
16 Nov 2016 12:42 PM
Linked lists are better than Lua arrays for iteration and removal
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
16 Nov 2016 04:12 PM
"Linked lists are better than Lua arrays for iteration and removal"
Uhm, no. Iteration is slightly faster using a regular Lua array obviously.
Report Abuse
EvilDonutNoob is not online. EvilDonutNoob
Joined: 26 Jan 2014
Total Posts: 440
03 Dec 2016 03:56 PM
^ (late post)

Maybe you are talking about indexing? Because incrementing index and dereferencing takes more steps than dereferencing itself, as done with lists.
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
03 Dec 2016 04:10 PM
"Maybe you are talking about indexing? Because incrementing index and dereferencing takes more steps than dereferencing itself, as done with lists."
no. Indexing is also faster with arrays. Linked-lists are only (theoretically) better with insertion and removal but that's not always true anymore.
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