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
 

Possible to print from table...

Previous Thread :: Next Thread 
Kondou is not online. Kondou
Joined: 05 Aug 2012
Total Posts: 1148
01 Sep 2013 04:49 PM
Is it possible to have the contents of a table go into a text label?

[WIJ Sergeant] Kondou
Report Abuse
ZachBloxx is not online. ZachBloxx
Joined: 26 Jun 2013
Total Posts: 2833
01 Sep 2013 04:56 PM
t = {1,2,3,4,5}
textLabel.Text = "Table Contents: " ..table.concat(t, ', ')
Report Abuse
Usering is online. Usering
Joined: 18 Aug 2012
Total Posts: 10281
01 Sep 2013 05:27 PM
@Zach, you should make it so when it hits the last object in the table it says: ", and " instead of just ","
Report Abuse
Iterations is not online. Iterations
Joined: 22 Jul 2013
Total Posts: 751
01 Sep 2013 05:35 PM
function concat(table)
local x,z = ""
for i,v in pairs(table) do
x = x..(not z and v or i<#table and ", "..v or ", and "..v)
z=true
end
return x
end
Report Abuse
BlueTaslem is not online. BlueTaslem
Joined: 11 May 2008
Total Posts: 11060
01 Sep 2013 05:38 PM
The above (iterations' post) will error on inputs that have non-integer indices. That means you should swap pairs for ipairs; since ipairs is less efficient it may be preferable to replace it with simple iteration from 1 to #table.
Report Abuse
Iterations is not online. Iterations
Joined: 22 Jul 2013
Total Posts: 751
01 Sep 2013 05:40 PM
dont use anything but numbahs D:

function concat(table)
local x,y,z = ""
for i,v in pairs(table)do y=i end
for i,v in pairs(table) do
x = x..(not z and v or i==y and ", "..v or ", and "..v)
z=true
end
return x
end

that should work
Report Abuse
Kondou is not online. Kondou
Joined: 05 Aug 2012
Total Posts: 1148
01 Sep 2013 05:41 PM
Thanks for the help guys, I got it to work.

One last question about tables. How can you clear everything in a table?

[WIJ Sergeant] Kondou
Report Abuse
KnightmareXD is not online. KnightmareXD
Joined: 14 Jul 2009
Total Posts: 11189
01 Sep 2013 05:41 PM
Table = { }
Report Abuse
Iterations is not online. Iterations
Joined: 22 Jul 2013
Total Posts: 751
01 Sep 2013 05:41 PM
function concat(table)
local x,y,z = ""
for i,v in pairs(table)do y=i end
for i,v in pairs(table) do
x = x..(not z and v or i~=y and ", "..v or ", and "..v)
z=true
end
return x
end
Report Abuse
ZachBloxx is not online. ZachBloxx
Joined: 26 Jun 2013
Total Posts: 2833
01 Sep 2013 05:42 PM
t = {1,2,3,4,5}
for i,v in pairs(t) do
table.remove(t,i)
end
Report Abuse
Iterations is not online. Iterations
Joined: 22 Jul 2013
Total Posts: 751
01 Sep 2013 05:43 PM
no that doesn't clear it
Report Abuse
BlueTaslem is not online. BlueTaslem
Joined: 11 May 2008
Total Posts: 11060
01 Sep 2013 05:43 PM
^ That will only affect the one reference.
If we have

a = {};
b = a;

Then

a = {}

will not empty b.

I'm not sure if this will actually delete the entries or just make them nil, but I believe it does:

for i,v in pairs(tab) do
tab[i] = nil;
end
Report Abuse
Usering is online. Usering
Joined: 18 Aug 2012
Total Posts: 10281
01 Sep 2013 05:44 PM
tab = {"hello","hi","lol",1,2,3}

table = {concat = function(tab, splice, lastSplice)
finishedString = ""
for i = 1,#tab do
if i == #tab then
finishedString = finishedString .. splice .. lastSplice .. tab[i]
elseif i == 1 then
finishedString = finishedString .. tab[i]
else
finishedString = finishedString .. splice .. tab[i]
end
end
return finishedString
end
}

print(table.concat(tab,", ","and "))
Report Abuse
Iterations is not online. Iterations
Joined: 22 Jul 2013
Total Posts: 751
01 Sep 2013 05:45 PM
@Taslem, that still wouldn't empty b.
Report Abuse
Iterations is not online. Iterations
Joined: 22 Jul 2013
Total Posts: 751
01 Sep 2013 05:47 PM
function concat(table,a,b)
local x,y,z = ""
for i,v in pairs(table)do y=i end
for i,v in pairs(table) do
x = x..(not z and v or i~=y and a..v or b..v)
z=true
end
return x
end

print(concat({4,6,7,A=4, B=true}, ", ", ", and "))

yer
Report Abuse
BlueTaslem is not online. BlueTaslem
Joined: 11 May 2008
Total Posts: 11060
01 Sep 2013 05:47 PM
...yes it will...?
Report Abuse
ZachBloxx is not online. ZachBloxx
Joined: 26 Jun 2013
Total Posts: 2833
01 Sep 2013 05:50 PM
Yes, Taslem's would work. Try this:

tab = {1,2,3,4,5}
print(unpack(tab))
for i,v in pairs(tab) do
tab[i] = nil
end
print(unpack(tab))
Report Abuse
Kondou is not online. Kondou
Joined: 05 Aug 2012
Total Posts: 1148
01 Sep 2013 05:54 PM
This one from Zach worked fine

t = {1,2,3,4,5}
for i,v in pairs(t) do
table.remove(t,i)
end

Thanks again.

[WIJ Sergeant] Kondou
Report Abuse
Iterations is not online. Iterations
Joined: 22 Jul 2013
Total Posts: 751
01 Sep 2013 06:04 PM
a = {1,2,3,4};
b = a;

for i,v in pairs(a) do
a[i]= nil
end

b will still be {1,2,3,4};

so
a = {1,2,3,4};
b = a

a = { }

b still equals {1,2,3,4};

so a = { } and for i,v in pairs(a)do a[i]=nil end are the same
Report Abuse
Iterations is not online. Iterations
Joined: 22 Jul 2013
Total Posts: 751
01 Sep 2013 06:05 PM
> t = {1,2,3,4,5}
for i,v in pairs(t) do
table.remove(t,i)
end print(unpack(t))

2 4

I don't see how that 'works'.
Report Abuse
luke111000 is not online. luke111000
Joined: 26 Apr 2009
Total Posts: 1853
01 Sep 2013 06:08 PM
Hey Kondou, if you need any help scripting, feel free to ask me and Lordjoe on Skype.
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