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
|
  |
| 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 |
|
|
|
| 09 Jul 2013 04:31 PM |
| string.concat(winners, ", ") |
|
|
| Report Abuse |
|
|
| |
|
Azarth
|
  |
| Joined: 17 Aug 2012 |
| Total Posts: 2760 |
|
| |
|
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 |
|
|
|
| 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
|
  |
| Joined: 17 Aug 2012 |
| Total Posts: 2760 |
|
|
| 09 Jul 2013 04:37 PM |
| My bad table.concat() did fix it, thanks. |
|
|
| Report Abuse |
|
|
|
| 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
|
  |
| Joined: 17 Aug 2012 |
| Total Posts: 2760 |
|
| |
|