mIRC Home    About    Download    Register    News    Help

Print Thread
#266752 27/01/20 01:08 PM
Joined: Aug 2012
Posts: 59
Maelish Offline OP
Babel fish
OP Offline
Babel fish
Joined: Aug 2012
Posts: 59
How would I detect if a minute from `$time` was even or odd?

Also, how would I use just the last digit from minutes as well? Meaning you'd be able to use 0 - 9.

Thanks in advance!


Find Gamers, my player finder for tabletop RPGers and Wargamers.
Maelish #266753 27/01/20 01:30 PM
Joined: Apr 2010
Posts: 969
F
Hoopy frood
Offline
Hoopy frood
F
Joined: Apr 2010
Posts: 969
You can get the last digit using something like

Code
echo -a $right( $time(n), 1)


and to check if something is even, you check if its a multiple of 2

Code
if (2 // $right( $time(n), 1)) {
  echo -a even
}
else {
  echo -a odd
}




References:
/help $right
/help $asctime
/help if-then-else

Last edited by FroggieDaFrog; 27/01/20 05:08 PM.

I am SReject
My Stuff
Maelish #266754 27/01/20 01:56 PM
Joined: Jul 2006
Posts: 4,145
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,145
Use $time(n) to get the number of minute and you can use $iif(N & 1,1,0) to know if a number is odd or not


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Maelish #266755 27/01/20 02:40 PM
Joined: Jan 2004
Posts: 2,127
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2004
Posts: 2,127
You would first floor-divide the ctime (number of seconds since year 1970) by 60 to obtain the number of minutes. Then you would get the modulo remainder from dividing that by 2, where 1 would indicate an odd number and 0 would indicate even. If you want it the other way around, use (1-result) instead of (result).

//echo -a $calc( ($ctime // 60) % 2) => $asctime

And for the last digit, since you're asking for a range size of 10 instead of odd-vs-even, the modulo would be 10 instead of 2

//echo -a $calc( ($ctime // 60) % 10) => $asctime

Last edited by maroon; 27/01/20 02:47 PM.
maroon #266756 27/01/20 04:12 PM
Joined: Aug 2012
Posts: 59
Maelish Offline OP
Babel fish
OP Offline
Babel fish
Joined: Aug 2012
Posts: 59
Ah, gotcha!

This either returns 0 (even) or 1 (odd).
Originally Posted by maroon
//echo -a $calc( ($ctime // 60) % 2) => $asctime

And this gives you the last digit for minute.
Originally Posted by maroon
//echo -a $calc( ($ctime // 60) % 10) => $asctime


Thanks @maroon!


Find Gamers, my player finder for tabletop RPGers and Wargamers.

Link Copied to Clipboard