| View previous topic :: View next topic |
| Author |
Message |
A Hylian Human Voice
Joined: 06 Sep 2010 Posts: 5
|
Posted: Sun Nov 28, 2010 6:44 pm Post subject: How to check for a valid variable without getting an error |
|
|
| Code: |
namespace eval rules {
set #Zelda("nick") "There is no need to spam nick changes; pick a nick and keep it! If you are in #RolePlay and need to change nicks frequently, please lea$
set #Zelda("flood") "Please do not flood (putting several lines of text into the channel at once) or spam (posting useless/irrelevant information). Consecu$
set #Zelda("ads") "Do not advertise any channels or servers. Do not advertise any TZCN channels on any other channels or servers."
set #Zelda("fights") "We ask that any arguments or fights be taken to another channel or private message."
set #Zelda("beg") "Do not beg for ops or moderator status. This includes attempting to use operator commands (including but not limited to !op, !up, !down,$
set #Zelda("mature") "Do not post grotesque or vulgar content. This includes, but is not limited to, shock sites, pornography, and explicit literature (ero$
set #Zelda("profanity") "Minor profanity is allowed. However, excessive swearing and discriminatory/racial slurs will be dealt with harshly."
set #Zelda("scripts") "While scripts can be humorous and fun, we ask that flood controls be implemented. Otherwise, your script will cause flooding, which $
set #Zelda("roleplay") "This channel (#Zelda) is meant for general discussion, not roleplaying. If you want to roleplay, join #RolePlay."
set #Zelda("nice") "The most important rule: be nice. Do not harass others be needlessly highlighting them (saying there name/nick). If they don't want to $
set #Zelda("agreement") "As with most communities, this chat room has rules. We (the moderators of this chat room) expect you to follow them at all times. $
set #Zelda("overview") "An overview of the rules: do not flood; do not post large amounts of text into the chat room, change nicks frequently, or rejoin th$
set #Zelda("unknown") "Unknown rule option. Syntax: !rule <option>. The options are:"
set #Zelda("options") [list "nick" "flood" "ads" "fights" "beg" "mature" "profanity" "scripts" "roleplay" "nice" "agreement" "overview" "default" "options"]
set #Hyrule_Castle("agreement") "You must keep this channel away from prying eyes (non-staff are not welcomed here)."
set #Hyrule_Castle("overview") "This is TZCN's Staff Channel. If you are not staff, get out. Otherwise, no rules. :)"
set #Hyrule_Castle("unknown") "Hey! There aren't any rules, okay!? Two options:"
set #Hyrule_Castle("options") [list "overview" "agreement"]
bind pub -|- "!rules" rules::showrules
proc showrules {nick uhost hand chan args} {
if { [set [subst $chan]("options")] == "" } { putnotc $nick "I do not know the rules for $chan. Be sure to ask the moderators." }
elseif {[lsearch $arg [set [subst $chan]("options")] != -1} { putnotc $nick [set [subst $chan]("options")] }
else {
join opts ", "
putnotc $nick "[set [subst $chan](unknown)] [set [subst $chan](options)]."
putnotc $nick "[set [subst $chan](agreement)]"
}
}
}
|
I'm trying to create a rules script. I can't seem to get it to work and my only solution (above) is turning out to be more complex than I had hoped.
Can someone help me?
I get this | Quote: | | Tcl error [rules::showrules]: can't read "#Hyrule_Castle("options")": no such variable | whenever I type
I just don't know what to do.  |
|
| Back to top |
|
 |
willyw Revered One
Joined: 15 Jan 2009 Posts: 1175
|
Posted: Sun Nov 28, 2010 9:25 pm Post subject: Re: How to check for a valid variable without getting an err |
|
|
Hello,
Regarding the topic of:
How to check for a valid variable without getting an error
How about this? :
[info exists variable]
reference: http://www.tcl.tk/man/tcl8.5/TclCmd/info.htm#M11
Could you use that, in an "if" statement, to do your checking?
| A Hylian Human wrote: | [code]
...
I'm trying to create a rules script. I can't seem to get it to work and my only solution (above) is turning out to be more complex than I had hoped.
...
|
As for this being the "only" solution... ... here's what I do, for what it may be worth -
I use this script:
holm-news.tcl 4.0 Displays the contents of a news file when a trigger is used.
found here:
http://www.egghelp.org/tclhtml/3478-4-0-0-1-holm-news.htm
to display channel rules.
I do change the trigger word.
All it does, is read a text file and display it.
Edit the script, and change the trigger to suit yourself, create a text file with your rules in it, and you are in business.
I hope one of these ideas helps. |
|
| Back to top |
|
 |
speechles Revered One

Joined: 26 Aug 2006 Posts: 1398 Location: emerald triangle, california (coastal redwoods)
|
Posted: Sun Nov 28, 2010 10:44 pm Post subject: Re: How to check for a valid variable without getting an err |
|
|
| A Hylian Human wrote: | I'm trying to create a rules script. I can't seem to get it to work and my only solution (above) is turning out to be more complex than I had hoped.
Can someone help me?
I get this | Quote: | | Tcl error [rules::showrules]: can't read "#Hyrule_Castle("options")": no such variable | whenever I type
I just don't know what to do.  |
The problem is very simple. You forgot to link your "global" variables to the "local" scope of your procedure. I've corrected your procedure below and commented the single line I added, and you had some line with ( join opts ", " ) which is not anything resembling tcl.. | Code: | proc showrules {nick uhost hand chan args} {
# here is the line i've added below
global #Zelda #Hyrule_Castle
if { [set [subst $chan]("options")] == "" } {
putnotc $nick "I do not know the rules for $chan. Be sure to ask the moderators."
} elseif {[lsearch $arg [set [subst $chan]("options")] != -1} {
putnotc $nick [set [subst $chan]("options")]
} else {
putnotc $nick "[set [subst $chan](unknown)] [join [set ::[subst $chan](options)] ", "]."
putnotc $nick "[set [subst $chan](agreement)]"
}
}
} |
Not sure really wtf this is supposed to do. So i've only corrected tcl errors, not any involving logic and such. _________________ speechles' eggdrop tcl archive |
|
| Back to top |
|
 |
A Hylian Human Voice
Joined: 06 Sep 2010 Posts: 5
|
Posted: Sun Nov 28, 2010 11:17 pm Post subject: |
|
|
Yeah I dunno what I was thinking.
But I came up with an idea that I think might work.
I'll post it tomorrow. |
|
| Back to top |
|
 |
nml375 Revered One
Joined: 04 Aug 2006 Posts: 2857
|
Posted: Mon Nov 29, 2010 4:11 pm Post subject: |
|
|
Since the variables are within a given namespace ("rules"), using global as suggested by speechles is incorrect. Instead, you should either use fully qualified namespace paths, or the "variable" command to link the variable from the current namespace into your proc.
For reading arrays, I'd suggest using the "array" command such as this:
| Code: | ...
somecommand [array get "::rules::$chan" options]
... |
_________________ NML_375, idling at #eggdrop@IrcNET |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|