mIRC Home    About    Download    Register    News    Help

Print Thread
#223260 20/07/10 12:13 AM
Joined: Mar 2006
Posts: 10
S
strac Offline OP
Pikka bird
OP Offline
Pikka bird
S
Joined: Mar 2006
Posts: 10
Is there a way to make a random timer?

strac #223263 20/07/10 02:15 AM
Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
You're going to have to clarify your meaning.

A basic timer consists of 3 parts.
1) The number of repetitions
2) The delay between each repetition
3) The command issued.

It's possible to randomize any one or even all of these, but the details depend on your specific requirements.

strac #223271 20/07/10 11:31 AM
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
And for the repetitions or delay, see /help $rand


Invision Support
#Invision on irc.irchighway.net
Riamus2 #223277 20/07/10 12:19 PM
Joined: Mar 2006
Posts: 10
S
strac Offline OP
Pikka bird
OP Offline
Pikka bird
S
Joined: Mar 2006
Posts: 10
I'm trying to get a timer to run at a random time.

Using signals I will be shutting the original timer that triggered the signal down and then starting another timer of the same name again at a random time to randomize the action.

strac #223278 20/07/10 12:27 PM
Joined: Feb 2006
Posts: 546
J
Fjord artisan
Offline
Fjord artisan
J
Joined: Feb 2006
Posts: 546
$rand(N,M) can be used to return a random integer between N and M (inclusive). if you want to start a timer that triggers at a random time between now and, for example, 4:00PM of the current day you can use:

Code:
//timer 1 $rand(0, $calc($ctime(16:00 $date) - $ctime)) <command>


"The only excuse for making a useless script is that one admires it intensely" - Oscar Wilde
jaytea #223284 20/07/10 04:13 PM
Joined: Mar 2006
Posts: 10
S
strac Offline OP
Pikka bird
OP Offline
Pikka bird
S
Joined: Mar 2006
Posts: 10
I figured out how to do it.
Code:
on 1:signal:start: /timer9 0 $rand(X,X) /signal go

Code:
on 1:signal:go:{
/timer9 off
/msg #room message
/signal start
}


Thank you all for your help.

Last edited by strac; 20/07/10 04:13 PM.
strac #223296 20/07/10 09:28 PM
Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
I've always been advised to not use a numeric as a timer name, though the actual reasoning for not doing so I don't recall any longer, but it seems to me it has something to do with the fact that mIRC automatically associates a numeric with each timer that is started.

RusselB #223298 20/07/10 10:48 PM
Joined: Jul 2006
Posts: 4,145
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,145
mIRC use an unique numeric timer name if you don't specify a name for your timer, that's it.
Using a numeric name is perfectly fine and is the same as using any other name

Last edited by Wims; 20/07/10 10:48 PM.

#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Wims #223316 21/07/10 03:10 AM
Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
OK. I thought that a numeric was assigned whether you specified a name or not.

Wims #223321 21/07/10 05:10 AM
Joined: Oct 2003
Posts: 3,918
A
Hoopy frood
Offline
Hoopy frood
A
Joined: Oct 2003
Posts: 3,918
That said, RusselB is correct. You should not use a numeric timer name. mIRC will auto-generate a unique name if none is given, but if mIRC already autogenerated timer9, the above script will overwrite it, which is bad. Consider:

Code:
//var %i = 1 | while (%i < 10) { /timer 1 2 echo -a %i | inc %i } | /timer9 1 1 echo -a NOT 9


You will get 1-8 and then "NOT 9" instead of 1-9 plus the *extra* NOT 9 message.

And because mIRC uses numeric values as autogenerated names, numbers, especially those < 10, are most likely to be in use and not really unique. A named timer is much safer.


- argv[0] on EFnet #mIRC
- "Life is a pointer to an integer without a cast"
argv0 #223322 21/07/10 05:56 AM
Joined: Jul 2006
Posts: 4,145
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,145
Your post is completely irrelevant for me, you're basically saying that we shouldn't run a timer that already exists because it will overwrite.
This is true whatever the name and the conclusion is the same in both case : you can use whatever the name you want for your new named timer but be sure this name isn't already used.

There's more chance that a timer name like 1,2,...,9 is already in use because of how mIRC automatically name a timer but it doesn't change anything at all, you should never assume that the name you're going to use isn't already used, and this either for "argv0", for "wims" or for "1", there is no "most likely" in such a case


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Wims #223324 21/07/10 06:12 AM
Joined: Oct 2003
Posts: 3,918
A
Hoopy frood
Offline
Hoopy frood
A
Joined: Oct 2003
Posts: 3,918
I'm saying you should not use numeric values for explicit timer names because there is a very high chance that you can overwrite an auto-generated timer name. Especially for values under 10. This seems pretty clear to me. I'm not sure why any sane person would argue against this statement.

Your point that "you should never assume the name isn't in use" is a little unrealistic. It's fairly reasonable for a scripter to assume "MYSCRIPT.MYTIMERNAME" would be unique to "MYSCRIPT" and unlikely to be used by anything else in mIRC. Heck, it's reasonable to even assume /timerRANDOMTIMER would be unused. It might not be guaranteed, but we're not discussing theoretics here. Using a name like "9" is far more likely to be in use than "SOMENAME", no matter what the name is, simply because mIRC auto-generates these timers. A few days in a STATS 101 class would teach you the practical differences between the above two names. It's not "the same", not in real world scenarios.

But you're right-- all of this is irrelevant. The above snippet uses a poorly named timer-- someone should have stated this. RusselB did, and he was right in doing so. Don't defend poor scripting practices. End of story.


- argv[0] on EFnet #mIRC
- "Life is a pointer to an integer without a cast"
argv0 #223332 21/07/10 07:35 AM
Joined: Jul 2006
Posts: 4,145
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,145
I'm not defending poor scripting practice, what I said still stand : you can use any timer name, it could be anything, obviously as long as you know it won't conflict with others timers, the fact that it has more chance to conflict with small numeric name is what I call irrelevant.
I didn't argue against your statement nor I said it wasn't clear, I agree with the recommendation, I would tell anyone that use '9' as a timer name to change it, just because it's impersonal.
But in my opinion that's the whole problem, we should be telling people to check the name they are going to use instead of telling them to use a name that is not likely to be used, which is, you know, the bad practice.


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Wims #223336 21/07/10 10:12 AM
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
There really isn't a good reason to check every single timer you use to see if it's in use. In addition, some timers WILL be in use by you and you want to overwrite them. So a check to see if it's in use wouldn't help in the first place in those situations.

Yes, you *might* overwrite a named timer accidentally, but the chances are so low as to be non-existent as long as you're not naming it something like mytimer or countdown or some other name that has a decent chance of being used by someone else (not as much as a numerical timer, but it's still high enough to avoid). As long as you name it something unique that isn't likely to be used by anyone else, then you don't need to check if it's in use. That's a waste of time and effort and in some cases, as mentioned, it's not possible to easily tell the difference if you want to overwrite your own timer but not an auto-generated timer.


Invision Support
#Invision on irc.irchighway.net

Link Copied to Clipboard