Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How do you get the last value in a table?

Asked by 5 years ago

Please include the code which you are trying to use, so the community will be better-equipped to help you with your problem.

Hi there, I'm not too good with tables and I am trying to figure out how to get the last value in the table? I already have a script that sets the table up. Basically I'm trying to get the last value from the table and set a text box to say the value that is displayed. The table is full of strings. Thanks :)

Table name is "Stations"

0
if it is an array, you can use the length operator to get the length of the table, and then use that to get the last value in an array. Ex: array[#array] theking48989987 2147 — 5y
0
so something like TextBox.Text = Stations[#] ? kieranhendy 28 — 5y
0
Stations[#Stations] Rheines 661 — 5y
0
^ TheMysticLynxx 89 — 5y
0
Thank you, Stations[#Stations] worked perfectly :) kieranhendy 28 — 5y

1 answer

Log in to vote
4
Answered by 5 years ago

Just use the unary operator, #.

local t = {"a","b","c","d","e"}

print(t[#t]) --> "e"
0
dang it... i was gonna say this... but goojob! starmaq 1290 — 5y
0
:)) Gey4Jesus69 2705 — 5y
Ad

Answer this question