mIRC Homepage

var vs. set

Posted By: AWEstun

var vs. set - 08/05/08 12:08 AM

What's the difference between /var and /set?

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

Re: var vs. set - 08/05/08 12:20 AM

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.
Posted By: AWEstun

Re: var vs. set - 08/05/08 12:33 AM

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
}
Posted By: RusselB

Re: var vs. set - 08/05/08 01:05 AM

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
}
Posted By: AWEstun

Re: var vs. set - 08/05/08 01:31 AM

So it doesnt have to end in an 'else'? If none of the 'if' match then nothing happens?
Posted By: AWEstun

Re: var vs. set - 08/05/08 03:11 AM

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.
Posted By: Lpfix5

Re: var vs. set - 08/05/08 03:28 AM

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
Posted By: genius_at_work

Re: var vs. set - 08/05/08 03:35 AM

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
Posted By: AWEstun

Re: var vs. set - 08/05/08 03:41 AM

Thanks.
Posted By: RusselB

Re: var vs. set - 08/05/08 03:51 AM

Quote:
So it doesnt have to end in an 'else'? If none of the 'if' match then nothing happens?
Correct
Posted By: AWEstun

Re: var vs. set - 08/05/08 04:01 AM

That and a bunch of 'cleanup' has resolved some weird 'run-away' script issues.
© 2019 mIRC Discussion Forums