mIRC Home    About    Download    Register    News    Help

Print Thread
#215738 04/10/09 03:51 AM
Joined: Jun 2004
Posts: 139
N
Ninko Offline OP
Vogon poet
OP Offline
Vogon poet
N
Joined: Jun 2004
Posts: 139
Hi there,
What does the switch -k do when using the /set command?

The manual says: The -k switch keeps the current -uN setting for a variable.

So I assumed it meant it will keep counting down even after changing the variable value, but it doesn't, eg...

Code:
set -ku30 %test123 1
%test123 = $calc(%test123 + 5)


The above stops the unset counter, so what does -k do and how can I change a variables value while keeping the unset time counting?

Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
Too tired to test this right now, but I think it means that the unset time will be retained even if mIRC is closed.

Normally global variables maintain there value even if mIRC is closed.

However, I don't think the delay for the unsetting of the variable is maintained if mIRC is closed, thus a variable would not be unset after mIRC is restarted, unless the -k switch is also included.

Joined: Nov 2006
Posts: 1,559
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Nov 2006
Posts: 1,559
Don't use the -k switch in the first set command (where you specify the unset time) but in your subsequent set-commands (where you assign some new value but want to keep it's unset time running).

Example:
Code:
alias settest {
  set -u5 %testX A
  ECHO -a set variable to value $var(testX,1).value $+ . unsets after $var(testX,1).secs secs.

  .timer -m 1 2500 newset
}

alias -l newset {
  set -k %testX B
  ECHO -a set variable to value $var(testX,1).value $+ . unsets after $var(testX,1).secs secs.
}

Joined: Jun 2004
Posts: 139
N
Ninko Offline OP
Vogon poet
OP Offline
Vogon poet
N
Joined: Jun 2004
Posts: 139
Code:
set -u30 %test123 1
while (5 >= %test123) {
  echo var: %test123
  set -k %test123 = $calc(%test123 + 1)
}


Why does the above code not echo 1-5 like it should? Instead it echos 1 and stops - %test123 = 2 at the end of the while loop.

Thanks


Ninko

Joined: Nov 2006
Posts: 1,559
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Nov 2006
Posts: 1,559
Your problem is caused by the "="-char in your /set -k command. While the use of "=" is recommended for /var commands, it's not part of the /set -syntax (...a common pitfall).
By setting your variable to the literal value "= 2", the condition of your while statement isn't met any more and the loop stops at "= 2". smile

Code:
  set -su30 %test123 1
  while (5 >= %test123) {
    set -sk %test123 $calc(%test123 + 1)
  }
Note the -s switches (useful for debugging).

Joined: Oct 2003
Posts: 3,918
A
Hoopy frood
Offline
Hoopy frood
A
Joined: Oct 2003
Posts: 3,918
In addition to what Horstl said, your code doesn't really make sense.

set -u30 implies the variable will stay set for 30 seconds. The time starts counting *after* your script has ended, but you immediately /set -k to stop this timer, making both switches unnecessary. Since the switches are not needed you can replace the latter /set command with a much simpler /inc command which increases by optional argument N (defaulting to 1).

The proper way to loop from 1 to 5 is simply:
Code:
var %i = 1
while (%i <= 5) { echo var: %i | inc %i }


Again, I'm not sure what you're trying to do, but -u/-k will have no effect within the same alias/event; they effectively cancel each other out.


- argv[0] on EFnet #mIRC
- "Life is a pointer to an integer without a cast"
Joined: Jun 2004
Posts: 139
N
Ninko Offline OP
Vogon poet
OP Offline
Vogon poet
N
Joined: Jun 2004
Posts: 139
Hi Horstl,
Thanks for your reply, what does the -s switch do, I can't see it in the manual?

Hi argv0,
What is the -k switch for then? From what I've tested the -k switch allows you to change the variable value while keeping the unset count going, which is what I want. How does it 'stop' it?


Ninko

Joined: Nov 2006
Posts: 1,559
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Nov 2006
Posts: 1,559
Like with many commands, -s in /set will echo the result to your status window.
(The helpfile lacks an explanation of -s at /set /unset /unsetall /dec and /inc; there's a brief note at /var only)

Joined: Jul 2006
Posts: 4,145
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,145
Quote:
Like with many commands, -s in /set will echo the result to your status window.
active*


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: May 2009
Posts: 139
E
Vogon poet
Offline
Vogon poet
E
Joined: May 2009
Posts: 139
-s is for status, -a is for active.


- Excalibur
- Good and Evil, there never is one without the other.
Joined: Jul 2006
Posts: 4,145
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,145
we're talking about /set, -s mean show and show what you've set, -a doesn't exists afaik

Last edited by Wims; 05/10/09 05:14 PM.

#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Nov 2006
Posts: 1,559
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Nov 2006
Posts: 1,559
$me stands corrected wink


Link Copied to Clipboard