Here's my attempt based on how its done in Python or Ruby
local list = {1,2,3,4} print(list[-1]) >> 4 ---------- local list = {A, C, D, R, G} print(list[-1]) >> G
list[-1] returns nil, is there an end of list reference in LUA might of just missed it but can't seem to find it in the docs, roblox or lua
*I can table.getn(list) and use that but I was just curious if there was something like the example above?
Well in lua, to get the last member of a table/ last element in a list, you would use the length operator, or #
, which is the easiest way of achieving this. This is the case as arrays in lua start at 1 instead of 0, unlike most other languages.
Also note that the getn function was deprecated in 5.1
Length operator
local tbl = {41,"owo",412,14,25,24,254,23} print(#tbl)--8 print(tbl[#tbl]) --23 print(tbl[8])--23
Hopefully this helped! And be sure to accept this answer if it did