This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

lindex issue

Old posts that have not been replied to for several years.
Locked
c
chicken

lindex issue

Post by chicken »

Hi,
Sorry if this sounds newbish, but I am new. I spent some time searching here and deja but cannot seem to find an answer. I want to be able to run a command like "@hi jimmy" and have it display something out of list. The problem is that I have variables in list that I want substituted, and it does not seem that lindex can do this. Is there another way to accomplish this?

Thanks!


bind pub o @hi pub_hi

set list {
"hi $args"
"hello $args"
}

proc pub_hi {nick mask hand channel args} {
global list
puthelp "PRIVMSG $channel :[lindex $list [rand [llength $list]]]"
}
User avatar
stdragon
Owner
Posts: 959
Joined: Sun Sep 23, 2001 8:00 pm
Contact:

Post by stdragon »

Use subst to substitute variables into text the way you're doing it.

But a better idea is to use your own variable names (like %nick instead of $nick) and then use regsub to substitute in fixed values. That's a lot more secure.
c
chicken

Post by chicken »

do you have an example of how to do this? I tried playing with that a little and could not get it to work either.

Thanks!
User avatar
stdragon
Owner
Posts: 959
Joined: Sun Sep 23, 2001 8:00 pm
Contact:

Post by stdragon »

If 'text' is the variable containing %nick that you want to substitute into,

regsub -all %nick $text $nick text
c
chicken

Post by chicken »

works perfect! thanks!
c
chicken

Post by chicken »

well spoke to soon :( It works the first time after a rehash or a restart, but then it just substitues the same things everytime after that. Pointers on what I am doing wrong?

Thanks
User avatar
stdragon
Owner
Posts: 959
Joined: Sun Sep 23, 2001 8:00 pm
Contact:

Post by stdragon »

Dunno, maybe you're using the wrong variable?

Remember that regsub modifies the string, so copy it to a temporary variable.
Locked