mIRC Home    About    Download    Register    News    Help

Print Thread
#203587 20/08/08 11:59 PM
Joined: Aug 2008
Posts: 4
C
C8889 Offline OP
Self-satisified door
OP Offline
Self-satisified door
C
Joined: Aug 2008
Posts: 4
Basically, i've written a script to update a counter once daily, once the IRC timestamp reaches the hour of 12 midnight -1 am.

I didn't know any way to fire this automatically, so I included it in an On:TEXT which is fired pretty often in the channel i use.

Only thing is though, the script doesn't seem to work. Would be much appreciated if you could lend a hand/suggest a way to improve it

It's basically a calender script using a custom calender for a game. The counter for %day is supposed to reset to 1 after 30, etc.
the %updated was how I figured was best to stop it from firing repeatedly

Code:
if (updated==0){
  if (0: isin $time)
  if (%day == 30) set %day 1
  /msg $chan %month %day , %year  

  else 
  %day = %day + 1
  set -u3600 %updated 1

} 

Last edited by C8889; 21/08/08 12:00 AM.
Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
Here's my suggestion
Code:
on me:*:join:#:{
  $+(.timer,$network,$chan) 0:00 1 0 checktime $network $chan
}
alias -l checktime {
  if %day == 30 {
    set %day 1
  }
  .msg $2 %month %day , %year
  $+(.timer,$1,$2) 0 86400 checktime $1 $2
}

Note: if you are already in the channel, you'll have to part, then re-join it (aka /hop)

Last edited by RusselB; 21/08/08 02:57 AM.
Joined: Jan 2004
Posts: 1,358
L
Hoopy frood
Offline
Hoopy frood
L
Joined: Jan 2004
Posts: 1,358
First of all, that wouldn't work because it isn't written properly. You're missing a number of { } which causes the ifs and else not work work as intended. Second, your script is dependent on being triggered by others at the right time, so if it isn't triggered at 0: (which is every 10 minutes, midnight, and 10 am) then you'll skip updating the day.

Code:
on *:start:{
  update_day
}

alias update_day {
  if ((!%begin) || (!%day)) {
    var -g %begin = $ctime
    var -g %day = 1
  }
  if ($ceil($calc(($ctime - %begin)/86400)) >= 30) {
    %begin = $ctime
    %day = 1
  }
  else %day = $v1
  .timerupdate.day -o 00:00 1 0 update_day
}


The timer is set to go off every day at midnight. The alias sets an initial time and then calculates how many days have passed since it started, and resets to 1 once it reaches 30. I'm not sure if it will work perfectly though. %begin may need to be the time at midnight.

edit: changed timer

Last edited by Loki12583; 21/08/08 03:49 AM.
Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
I'm sorry, but I must disagree.
1) The braces that you seem to think were missing are not there because that section of the code was set to run no matter if the condition matched or not, therefore that part of the code does not qualify as an ELSE

2) The initial code (ON JOIN event) sets a single timer that is run once at 0 seconds past midnight (00:00)

3) The script is only dependent on the initial ON JOIN event, as the timers are set to use the network name and channel name, and the ON JOIN event is marked to only be recognized when the person/bot with the code joins the channel.. not anyone else.

Finally, looking at your code, you have the timer set to fire at 0 seconds after midnight and indefinetely. I just did a quick test of this method, and it runs constantly starting at the initial time (ie: 0 seconds after midnight)

My apologies, Loki.. I missed the fact that you were replying directly to the OP, and not to me in regards to my code.

Last edited by RusselB; 21/08/08 03:40 AM.
Joined: Jan 2004
Posts: 1,358
L
Hoopy frood
Offline
Hoopy frood
L
Joined: Jan 2004
Posts: 1,358
That's alright Russel, I had clicked reply before you posted and didn't see yours. When I posted I hoped you wouldn't confuse who I had directed my post too, but oh well. I've updated the timer on my script.


Link Copied to Clipboard