Converting seconds to hours, minutes and seconds
#9

pawn Code:
stock secs2hms(secs,&hours,&minutes,&seconds) {if (secs<0) return false;minutes = secs / 60; seconds = secs % 60;hours = minutes / 60; minutes = minutes % 60;return 1;}
Notic, I changed public to stock.. public is not needed here at all. You don't need to call it ouside the script.

now notice the &hours, & ... , the & sign means you pass a variable by reference, so the function will actually SET that variable, it's like you provide more than 1 output variable, if no & (however eg arrays are exceptions, eg strcopy) it means it's input [again, arrays are exceptions, I won't go deeper into it],
Now we want to know how many hours, mins, seconds , 3661 seconds is,
we start making our variables:
pawn Code:
new MyKnownSeconds = 3661;
new Seconds;
new Minutes;
new Hours;
now we execute our function, not at global level because that will cause errors, we execute it locally (thus inside another function/public)
pawn Code:
public OnFilterScriptInit()
{
new MyKnownSeconds = 3661;
new Seconds;
new Minutes;
new Hours;
secs2hms(/*input*/ MyKnownSeconds, /*output*/Hours,Minutes,Seconds);//Assign Hours,Minutes,Seconds the correct values, you can replace MyKnownSeconds by an number also, eg 3661
printf("H: %d M: %d S: %d",Hours,Minutes,Seconds);
return 1;
}
this will print:
Code:
H: 1 M: 1 S: 1
If you need more lemme know..
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)