mIRC Home    About    Download    Register    News    Help

Topic Options
#199019 - 08/05/08 01:08 AM var vs. set
AWEstun Offline
Fjord artisan

Registered: 02/05/08
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.

Top
#199021 - 08/05/08 01:20 AM Re: var vs. set [Re: AWEstun]
RusselB Offline
Planetary brain

Registered: 03/08/04
Posts: 7252
Loc: Ontario, Canada
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.

Top
#199023 - 08/05/08 01:33 AM Re: var vs. set [Re: RusselB]
AWEstun Offline
Fjord artisan

Registered: 02/05/08
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.

Top
#199029 - 08/05/08 02:05 AM Re: var vs. set [Re: AWEstun]
RusselB Offline
Planetary brain

Registered: 03/08/04
Posts: 7252
Loc: Ontario, Canada
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
}

Top
#199030 - 08/05/08 02:31 AM Re: var vs. set [Re: RusselB]
AWEstun Offline
Fjord artisan

Registered: 02/05/08
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.

Top
#199033 - 08/05/08 04:11 AM Re: var vs. set [Re: AWEstun]
AWEstun Offline
Fjord artisan

Registered: 02/05/08
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.

Top
#199036 - 08/05/08 04:28 AM Re: var vs. set [Re: AWEstun]
Lpfix5 Offline
Hoopy frood

Registered: 10/08/05
Posts: 1052
Loc: Canada
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* }

Top
#199038 - 08/05/08 04:35 AM Re: var vs. set [Re: AWEstun]
genius_at_work Offline
Hoopy frood

Registered: 08/10/05
Posts: 1741
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

Top
#199040 - 08/05/08 04:41 AM Re: var vs. set [Re: genius_at_work]
AWEstun Offline
Fjord artisan

Registered: 02/05/08
Posts: 329
Thanks.
_________________________
I registered; you should too.

Top
#199041 - 08/05/08 04:51 AM Re: var vs. set [Re: AWEstun]
RusselB Offline
Planetary brain

Registered: 03/08/04
Posts: 7252
Loc: Ontario, Canada
Quote:
So it doesnt have to end in an 'else'? If none of the 'if' match then nothing happens?
Correct

Top
#199043 - 08/05/08 05:01 AM Re: var vs. set [Re: RusselB]
AWEstun Offline
Fjord artisan

Registered: 02/05/08
Posts: 329
That and a bunch of 'cleanup' has resolved some weird 'run-away' script issues.
_________________________
I registered; you should too.

Top