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

Ok, here you go... readymade solution..

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

1
2
3
4
5
6
7
8
9
10
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)

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

No need to pay mate.. just give me free copy of your app :D :D :D

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..

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

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!

views:1392 update:2011/9/30 9:15:39
corona forums © 2003-2011