What's the difference between /var and /set?
Which should I be using and why, if my scipt is all in one file?
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.
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?
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
}
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
raw 205:*:{
if (%ontext) {
...
unset %ontext
}
elseif (%onjoin) {
...
unset %onjoin
}
elseif (%smatch) {
...
unset %smatch
}
haltdef
}
So it doesnt have to end in an 'else'? If none of the 'if' match then nothing happens?
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.
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
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
That and a bunch of 'cleanup' has resolved some weird 'run-away' script issues.