Leander Tyles Posted May 24, 2013 Share Posted May 24, 2013 please help me with time convertor problem,string ts2Days(integer unixExpiration){ integer seconds = unixExpiration - llGetUnixTime(); integer weeks = seconds / 604800; integer days = seconds / 86400; integer hours = (seconds % 86400) / 3600; integer mins = (seconds % 3600) / 60; string time = ""; if (weeks) { time += (string)weeks + " week"; if (~-weeks) time += "s"; time += " "; } if (days) { time += (string)days + " day"; if (~-days) time += "s"; time += " "; } if (hours) { time += (string)hours + " hour"; if (~-hours) time += "s"; time += " "; } if (mins) { time += (string)mins + " min"; if (~-mins) time += "s"; } if (days < 4) return time + ",EXPIRING"; else if (days > 6) return time + ",SUPERB"; else return time + ",OK";}when i rent or extend my lease to be told how much time i have left, it`ll say something like this[LEASE EXTENDED] Time left: 2 weeks 16 days 21 hours 54 minsthats the issue ^i dont realy have 2 weeks and 16 days left, - thiers just 2 weeks IN 16 days with TWO days left over.so instead of saying what it does, it should say Time left: 2 weeks 2 days 21 hours 54 mins ive looked at several open source scripts but they dont do weekshttp://wiki.secondlife.com/wiki/Rental_Cubehttp://patrioticnigras.org/wiki/index.php?title=Rental_Script Link to comment Share on other sites More sharing options...
Nova Convair Posted May 24, 2013 Share Posted May 24, 2013 integer days = (seconds % 604800) / 86400; Link to comment Share on other sites More sharing options...
Leander Tyles Posted May 24, 2013 Author Share Posted May 24, 2013 thank you, that done the trick it caused a new problem now tho which i dunno how to solve, with the last part of the code if (days < 4) return time + ",EXPIRING"; else if (days > 6) return time + ",SUPERB"; else return time + ",OK"; it always says "OK" even if i rent far in advance. Link to comment Share on other sites More sharing options...
Ron Khondji Posted May 24, 2013 Share Posted May 24, 2013 This does what you´re looking for, I think: if (weeks) time += ", SUPERB"; else if (days >= 4) time += ", OK"; else time += ", EXPIRING"; return time; Link to comment Share on other sites More sharing options...
Leander Tyles Posted May 24, 2013 Author Share Posted May 24, 2013 great tyvm ah another problem occured, i almost overlooked.... the old code worked string ts2Days(integer unixExpiration) { integer seconds = unixExpiration - llGetUnixTime(); integer weeks = seconds / 604800; integer days = (seconds % 604800) / 86400; integer hours = (seconds % 86400) / 3600; integer mins = (seconds % 3600) / 60; string time = ""; if (weeks) { time += (string)weeks + " week"; if (~-weeks) time += "s"; time += " "; } if (days) { time += (string)days + " day"; if (~-days) time += "s"; time += " "; } if (hours) { time += (string)hours + " hour"; if (~-hours) time += "s"; time += " "; } if (mins) { time += (string)mins + " min"; if (~-mins) time += "s"; } /* if (days < 4) return time + ",EXPIRING"; else if (days > 6) return time + ",SUPER"; else return time + ",OK"; */ return time; } rental time is returned fine for example: Your rent expires in 6 days 23 hours 50 mins but when i use your code i get Your rent expires in 6 days 23 hours 53 mins,OK notice the OK ^ in the msg time += ", OK"; i tried removing the space between the , and OK but that didnt do the job i have no idea what the problem is... then again i didnt earlier either Link to comment Share on other sites More sharing options...
Leander Tyles Posted May 24, 2013 Author Share Posted May 24, 2013 i got it working, removing the = signs helped... i dont understand it but im glad i tried it time + ", OK" ah damnit, everytime i think i fixed something, another issue occurs if i leave the += signs in, then timeleft aint displayed on my dialogs if i do it myway just the + signs, then timeleft is displayed but the status which is (OK/EXPIRING/SUPERB) aint displayed so frustrating Link to comment Share on other sites More sharing options...
Leander Tyles Posted May 24, 2013 Author Share Posted May 24, 2013 okie after comparing all the codes given to me, i done it this way if (weeks) return time + ",SUPERB"; else if (days >= 4) return time + ",OK"; else return time + ",EXPIRING"; which has seemed to work i put RETURN before each one.... ive no idea why thats any different but if it works it works OMG im back to the origional problem again Your rent expires in 6 days 23 hours 53 mins,SUPERB <<<< maybe i can parse the string ???? never had to in the past using the first code "\nYour rent expires in " + ts2Days(unixExpiration)); Link to comment Share on other sites More sharing options...
Ron Khondji Posted May 24, 2013 Share Posted May 24, 2013 So you want the time and a seperate status.I would just a global variable for the status and do: string status;string ts2Days(integer unixExpiration) { integer seconds = unixExpiration - llGetUnixTime(); integer weeks = seconds / 604800; integer days = (seconds % 604800) / 86400; integer hours = (seconds % 86400) / 3600; integer mins = (seconds % 3600) / 60; string time = ""; if (weeks) { time += (string)weeks + " week"; if (~-weeks) time += "s"; time += " "; } if (days) { time += (string)days + " day"; if (~-days) time += "s"; time += " "; } if (hours) { time += (string)hours + " hour"; if (~-hours) time += "s"; time += " "; } if (mins) { time += (string)mins + " min"; if (~-mins) time += "s"; } if (weeks) status = "SUPERB"; else if (days >= 4) status = "OK"; else status = "EXPIRING"; return time;}default { state_entry() { llSay(0, "Rent expires in: " + ts2Days( llGetUnixTime() + (2 * 86400) + (3 * 3600))); llSay(0, "Status is " + status); }} Link to comment Share on other sites More sharing options...
Recommended Posts
Please take a moment to consider if this thread is worth bumping.
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now