Help with Simple Script (Paid)

Hi everyone,

I’m somewhat new to coding in LUA. I just need to sort some data by date. I’ve attached what I have so far. I can sort by month but its not sorting by day.

I want to sort from newest to oldest. I’m sorting a lot of files so it needs to be fast.

I’m willing to pay you via paypal for your help.

The code is below.

local runAgain = false

local function sortTable(tbl)
for i = 2, #fileInfo -1 do
–keep a temporary backup
local temp = fileInfo[i];
–do checks
if fileInfo[i - 1].creationTime.year > fileInfo[i].creationTime.year and fileInfo[i - 1].creationTime.month > fileInfo[i].creationTime.month and fileInfo[i - 1].creationTime.day > fileInfo[i].creationTime.day and fileInfo[i - 1].creationTime.hour > fileInfo[i].creationTime.hour and fileInfo[i - 1].creationTime.min > fileInfo[i].creationTime.min and fileInfo[i - 1].creationTime.second > fileInfo[i].creationTime.second then
–swap items
fileInfo[i] = fileInfo[i - 1];
fileInfo[i - 1] = temp;
–set boolean
runAgain = true;
end
–reset
if i == #fileInfo -1 and runAgain == true then
i = 1;
runAgain = false;
break
end
end
end
[import]uid: 40156 topic_id: 10241 reply_id: 310241[/import]

Ok, here you go… readymade solution…

this is assuming, year is 4 digit no., month is 2 digit no and so on…

[lua]function compareFileTimeStamp(a,b)
local file1timestamp = a.creationTime.year*10^10 + a.creationTime.month*10^8 + a.creationTime.day*10^6 + a.creationTime.hour*10^4 + a.creationTime.min*10^2 + a.creationTime.second

local file2timestamp = b.creationTime.year*10^10 + b.creationTime.month*10^8 + b.creationTime.day*10^6 + b.creationTime.hour*10^4 + b.creationTime.min*10^2 + b.creationTime.second

return file1timestamp > file2timestamp
end
table.sort(fileInfo, compareFileTimeStamp)[/lua] [import]uid: 48521 topic_id: 10241 reply_id: 37381[/import]

This works great…I’m happy to submit a few dollars via paypal for your help.

Why are we doing year*10 to the 10th power?
Why is month*10 to the 8th power?

Thanks again [import]uid: 40156 topic_id: 10241 reply_id: 37387[/import]

No need to pay mate… just give me free copy of your app :smiley: :smiley: :smiley:
Why are we doing year*10 to the 10th power?
Why is month*10 to the 8th power?

This is to convert your file time info into something comparable in 1 step. i.e I am comparing two numbers which represent timestamps in following format : YYYYMMDDhhmmss

another long way to do would have been to compare YYYY first , if they are same then compare MM , if they are same then compare DD… and so on… [import]uid: 48521 topic_id: 10241 reply_id: 37389[/import]

Thanks again, yes, you will definitely have a free download code when it’s ready.

[import]uid: 40156 topic_id: 10241 reply_id: 37390[/import]

I apologize for bothering you with a new question, I hit a wall and can’t figure it out.

Im having trouble saving sprite set data to a json file for loading later…

Here is how my sprite sheets are set up

local mySheet = sprite.newSpriteSheetFromData(“myImage.png”, require(“mySet”).getSpriteSheetData())
local mySet = sprite.newSpriteSet(mySheet, 1, 15)
sprite.add(mySet,“MyAnim”, 1, 15, 500, 1)

Any ideas on how I can save the mySet data to json?

Thank you again!
[import]uid: 40156 topic_id: 10241 reply_id: 37934[/import]