Get Second and Minutes from Seconds
#1

I gave it a try, but I'm terrible at this stuff. I want to return the minutes, and seconds from the total seconds. If anybody can give my some tips, that would be great.
Reply
#2

Hey Use ******
Goto ******
Type "Yours Mints In Seconds"
Like:http://postimage.org/image/1qtat3lgk/
Reply
#3

I did this one in 3 mins. It MIGHT not work, since I can't test it, but if it does, feel free to use it.

pawn Код:
stock MinutesInSeconds(seconds) /* Minutes In Seconds by Admantis */
{
    if (seconds < 60) return printf("seconds could not converted in minutes");
    new mins, string[64];
    for(new s = 0; s < seconds; s++)
    {
        if (s == 60)
        {
            s = 0;
            mins++;
        }
    }
    printf("%i:%i", mins, s);
    /*format(string, sizeof(string), "%i:%i", mins, s);
    SendClientMessageToAll(0xFFFFFFAA, string);*/

    return true;
}
Reply
#4

http://forum.sa-mp.com/showpost.php?...&postcount=973

Ask me on msn if you have problems using it.
Reply
#5

Quote:
Originally Posted by ******
Посмотреть сообщение
Why is seconds not passed by reference, surely if you pass "3333" seconds you would want to know that that is 55 minutes and 33 seconds? And why do you return a string AND the values? A function should really only do one or the other - doing both is a waste of time if you only want one. Also:

pawn Код:
#define CT(%0) ((%0)==1)?(""):("s"))
format(str, sizeof (str), "%d minute%s", d, CT(d));
Even if you do use the other method, there's no need for the # within the macro as the parameters are already strings. # is used to convert non-strings to strings, anything inside ""s are already strings.
Thanks for pointing out the seconds param not having a reference!

I guess you can call the seconds issue a sort of goof. It was removed when i was testing just so i could have a literal integer there instead (im lazy). The version that i actually use has it as a reference. I'll update the post i made, and actually fix that. I should've saw this when i was making an example for the thread, as i also used a literal integer there as well. Sorry for that, I'll fix it up (the entire post :P).


As for the macro, its just a reusable macro i made for things like format. I got sick of having to do:

Код:
format(String,sizeof(String), "There are %d %s left", Var, (Var == 1) ? ("second") : ("seconds"));
It wasn't made exactly for this function (im lazy, and like to shorten code with macro's ... even though macro's are tought to be the "devil" and should be avoided like the plague in other languages). I could very well use your macro, but i use my out of comfort really, nothing more (i've used it for so long im used to it :\). I know about the stringize operator (not as well as you, since you wrote the thing haha), the "#" is there for insurance, and wont actually affect speed in anyway since its not used at run-time.

The references are because not everyone wants a string with the time, some people may want to format it their own way, or save it (for some...odd reason. I would just save a unix timestamp, but w/e). I wanted it to fit everyone's needs.
Reply
#6

if you do it in a calacator like this


1minute = 60seconds

10mins = 600seconds

just do 60 x How Many Minutes
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)