#OS.DATE() and tableToString() functions
Each item in os.date("!*t") has a key and a value.
You can get values inside the table such as the time by saying (os.date variable).key:
currentTime = os.date("!*t")
print(currentTime.hour)
print(currentTime.min)
print(currentTime.day)
print(currentTime.month)
See later in the post for a complete list of keys that the table os.date("!*t") contains
Anyway, your code should be:
function tableToString(tableToConvert)
local resultString = ""
for key, value in pairs(tableToConvert) do
resultString = resultString .. tostring(key) .. ": " .. tostring(value) .. "\n"
end
return resultString
end
while true do
local date_table = os.date("!*t")
print(date_table)
local resultString = tableToString(date_table)
print(resultString)
script.Parent.TextLabel.Text = resultString
wait (1)
end
Output should look similar to this:
table: 0xee2ed6d66812dd73 <
hour: 22
min: 16
wday: 7
day: 30
month: 11
year: 2019
sec: 6
yday: 334
isdst: false
hour, min, wday, day, month, year, sec,yday, isdst are all the keys inside the table os.date("!*t")
#UNPACK()
unrelated but, this is unpack() that i was talking about earlier:
myTable = {"this is a value", "this is another value", 123, 4354353454}
print(unpack(myTable))
output:
this is a value this is another value 123 4354353454
unpack() doesn't work for dictionaries (the type of table you're trying to print)
if you did this it would print out nothing vvvvvvv
local date_table = os.date("!*t")
print(unpack(date_table))
2 comments
It returned this pack: function: the whole table probably
?