mIRC Home    About    Download    Register    News    Help

Print Thread
#199019 08/05/08 12:08 AM
Joined: May 2008
Posts: 329
A
AWEstun Offline OP
Fjord artisan
OP Offline
Fjord artisan
A
Joined: May 2008
Posts: 329
What's the difference between /var and /set?

Which should I be using and why, if my scipt is all in one file?


I registered; you should too.
AWEstun #199021 08/05/08 12:20 AM
Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
Simply put /var creates local variables. These automatically get unset when the script ends. /set creates global variables which stay until you unset them either manually or in the code.

Which one you use depends on if you want/need the information to be saved between each run of the script. If you are using dynamic variables in the format of $+(%,variable,name) have to be set using the /set command, but can be set using /var if you use the format of % $+ variable $+ name

It depends on if the first character in the statement setting the dynamic variable is % or not.

RusselB #199023 08/05/08 12:33 AM
Joined: May 2008
Posts: 329
A
AWEstun Offline OP
Fjord artisan
OP Offline
Fjord artisan
A
Joined: May 2008
Posts: 329
Okay, then that brings up my next question. Lets say I have an ON TEXT and any time someone says something on the room, I want to trace them. Now under the RAW Trace code I have several 'if' statements. So back in the ON TEXT I have 'set %ontext $true'. Then under the RAW Trace when it gets to the 'if (%ontext) { ...' it'll execute. Then at the end of that 'if' I have 'set %ontext $false' so that when the RAW trace gets called from something else like ON JOIN the ON TEXT 'if' wont get executed. Is this right?

Code:
raw 205:{
  if (%ontext) {
    ...
    set %ontext $false
  }
  elseif {
    if (%onjoin) {
      ...
      set %onjoin $false
    }
  else {
    if (%smatch) {
      ...
      set %smatch $false
    }
haltdef
}

on *:join:#: {
  ...
  set %onjoin $true
  trace $nick
}

on *:text:*:#: {
  ...
  set %ontext $true
  trace $nick
}


I registered; you should too.
AWEstun #199029 08/05/08 01:05 AM
Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
Basic idea is correct.. also, you can use unset %variable rather than set %variable $false

You have a slight coding error in the raw section
Code:
raw 205:*:{
  if (%ontext) {
    ...
    unset %ontext
  }
  elseif (%onjoin) {
    ...
    unset %onjoin
  }
  elseif (%smatch) {
    ...
    unset %smatch
  }
  haltdef
}

RusselB #199030 08/05/08 01:31 AM
Joined: May 2008
Posts: 329
A
AWEstun Offline OP
Fjord artisan
OP Offline
Fjord artisan
A
Joined: May 2008
Posts: 329
So it doesnt have to end in an 'else'? If none of the 'if' match then nothing happens?


I registered; you should too.
AWEstun #199033 08/05/08 03:11 AM
Joined: May 2008
Posts: 329
A
AWEstun Offline OP
Fjord artisan
OP Offline
Fjord artisan
A
Joined: May 2008
Posts: 329
Can unset have more than one variable on it's line?

unset %a, %b

I can't get it to work that way, but

unset %a
unset %b

does work.


I registered; you should too.
AWEstun #199036 08/05/08 03:28 AM
Joined: Aug 2005
Posts: 1,052
L
Hoopy frood
Offline
Hoopy frood
L
Joined: Aug 2005
Posts: 1,052
or you can name your variables like %on.join %on.part or whatever and unset them all one shot by typing /unset %on.*

* becomes a wildcard so anything after before the * if theres a match it will unset

thats why you see many scripters write their script with something like %mine.a %mine.b %mine.c %mine.d so they all could unset it one shot if needed with a wildcard


Code:
if $reality > $fiction { set %sanity Sane }
Else { echo -a *voices* }
AWEstun #199038 08/05/08 03:35 AM
Joined: Oct 2005
Posts: 1,741
G
Hoopy frood
Offline
Hoopy frood
G
Joined: Oct 2005
Posts: 1,741
You can unset multiple variables by separating them with spaces, not commas.

/unset %a %b %c

unsets %a and %b and %c


Or by using wildcards as described above.

/unset %a*

unsets %abc and %a and %a.bc


Also, you can use the $+ command without $eval-ing the result.

/unset %ab $+ c

unsets %abc


-genius_at_work

Joined: May 2008
Posts: 329
A
AWEstun Offline OP
Fjord artisan
OP Offline
Fjord artisan
A
Joined: May 2008
Posts: 329
Thanks.


I registered; you should too.
AWEstun #199041 08/05/08 03:51 AM
Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
Quote:
So it doesnt have to end in an 'else'? If none of the 'if' match then nothing happens?
Correct

RusselB #199043 08/05/08 04:01 AM
Joined: May 2008
Posts: 329
A
AWEstun Offline OP
Fjord artisan
OP Offline
Fjord artisan
A
Joined: May 2008
Posts: 329
That and a bunch of 'cleanup' has resolved some weird 'run-away' script issues.


I registered; you should too.

Link Copied to Clipboard