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.

treating variables in strings as text

Old posts that have not been replied to for several years.
Locked
G
Guest

Post by Guest »

To simplify the use of the script im writing, i want the user to be able to have total control over the output. To make this possible i want the user to able to define how the output should look using a global variable and then simply put some kind of marker (or variable) in the output string where the dynamic data will be put.

An example:

# In this string $dynamic could be placed wherever the user wants, and the rest could be whatever text the user want
set mystring "hello $dynamic eat more eggdrop soup"

proc output_something {some_arg somechan} {
global mystring
set dynamic $some_arg
putserv "$somechan :$mystring"
}

You see the problem. This will of course make the bot to puke. So if i could prevent $dynamic from being evaluated the first time it will work fine.

Im just not sure if its doable. If it is, the solution eludes me.
So can it be done? If not, can someone think of another way to achieve the result i want?

Someone must have spent some mindwork on this kind of problem before...
G
Guest

Post by Guest »

Oh nevermind..

I solved the problem using regsub inside the proc... :wink:
User avatar
stdragon
Owner
Posts: 959
Joined: Sun Sep 23, 2001 8:00 pm
Contact:

Post by stdragon »

Well I guess it's too late, now, but if you were still wondering how to do it your original way, try this:

set mystring {hello $dynamic eat more eggdrop soup}

proc output_something {some_arg somechan} {
global mystring
set dynamic $some_arg
set newstring [subst $mystring]
putserv "$somechan :$newstring"
}
Locked