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 + concatenation

Previous Thread :: Next Thread 
Azarth is not online. Azarth
Joined: 17 Aug 2012
Total Posts: 2760
09 Jul 2013 04:30 PM
How would I print a table of items that after than concatenate a sentance? The way I'm doing it now just prints "Popeye, ". If I don't concatenate, then it prints correctly -
"Popeye and SUPERMAN"


local winners = {"SUPERMAN", "POPEYE"} --Just for testing so I don't have to start server.
if #winners == 1 then
notify(winners[1].. " won with "..hs.. " kills!")
elseif #winners >= 2 then
local tab = {}
for i = 1, #winners do
if i == #winners then
table.insert(tab, " and "..winners[i]..".")
else
table.insert(tab, winners[i]..",")
end
end
notify(unpack(tab).. " tied with "..hs.. " kills.") --Should I even be using unpack? This is my first attempt.
else
notify("No one won. How is that even possible?!?!")
end
Report Abuse
Azarth is not online. Azarth
Joined: 17 Aug 2012
Total Posts: 2760
09 Jul 2013 04:31 PM
*How would I print a table of items and concatenate a sentence after?
Report Abuse
Notunknown99 is not online. Notunknown99
Joined: 05 Sep 2008
Total Posts: 25360
09 Jul 2013 04:31 PM
string.concat(winners, ", ")
Report Abuse
Notunknown99 is not online. Notunknown99
Joined: 05 Sep 2008
Total Posts: 25360
09 Jul 2013 04:32 PM
Sorry, table.concat
Report Abuse
Azarth is not online. Azarth
Joined: 17 Aug 2012
Total Posts: 2760
09 Jul 2013 04:32 PM
Ah, thanks!
Report Abuse
Azarth is not online. Azarth
Joined: 17 Aug 2012
Total Posts: 2760
09 Jul 2013 04:34 PM
Wait, nvm. I have the spacing correct(concat is obv better), but I'm having trouble adding the " won with hs" bit at the very end. Trying to add that now is only getting the first person in the table then stopping.
Report Abuse
Notunknown99 is not online. Notunknown99
Joined: 05 Sep 2008
Total Posts: 25360
09 Jul 2013 04:36 PM
What do you mean? If there are 2 people in the table it only says the first person in the table?
Report Abuse
Azarth is not online. Azarth
Joined: 17 Aug 2012
Total Posts: 2760
09 Jul 2013 04:37 PM
My bad table.concat() did fix it, thanks.
Report Abuse
Notunknown99 is not online. Notunknown99
Joined: 05 Sep 2008
Total Posts: 25360
09 Jul 2013 04:40 PM
BTW: Do you still do the tab bit? Because you could do it without any if statements, only ternary operators.
Report Abuse
Azarth is not online. Azarth
Joined: 17 Aug 2012
Total Posts: 2760
09 Jul 2013 04:42 PM
Oh, good idea.
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