mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Sep 2003
Posts: 5
G
gabaod Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
G
Joined: Sep 2003
Posts: 5
Looking for exampled of something i feel is pretty basic smile

ie:

set %chan bleh

set %chan%tt00 lalalala

where that last line in reality would have a variable name of blehtt00 represeting the line lalalala

basically i have a script that has the word *chan* as part of many variables, and i want to create that word *chan* to be a variable so that at the top of the script i can change that word with changing just one setting.

in tcl it would be
set chan bleh
[set chan]tt00 would in affect be 'blehtt00' as the variable name, lookin on howto do same thing in mirc scripting, i also posted this in a bitchx forum as well, so if someone happens to know howto do that in bitchx as well, please post as well smile

Joined: Aug 2003
Posts: 37
R
Ameglian cow
Offline
Ameglian cow
R
Joined: Aug 2003
Posts: 37
one method is like this:

set %channel-prefix dinner
set %channel $+(%channel-prefix, _for_two)

which leaves %channel as "dinner_for_two"

Joined: Sep 2003
Posts: 5
G
gabaod Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
G
Joined: Sep 2003
Posts: 5
finally got someone on irc to respond hehe

they stated to do this

set %channel mychan
set % $+ %channel $+ newvar mychan2

which creates %mychannewvar mychan2

gonna go home from work to test soon, otherwise ill try your way

Joined: Sep 2003
Posts: 5
G
gabaod Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
G
Joined: Sep 2003
Posts: 5
ahh nm, looked at your syntax again.

what youre doing is combinging the output of the 2 variables together..

what i was asking about is combinging the output of var1, to the beginning of the next variable name, not the output of the next variable

Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
Play with these things yourself a bit, using /set -s

//var %two = 2 | set -s %one $+ %two 3 | set -s $+(%,one,%two) 3 | set -s $+(%one,%two)

Try this command. You'll see that the first two /set commands do exactly the same thing, which I hope is what you want, while the 3rd causes an error.


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
Joined: Sep 2003
Posts: 5
G
gabaod Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
G
Joined: Sep 2003
Posts: 5
im NOT wanting to combine the ouputs of each var together..

ill try to state it one more time

var1 = cat

so anytime i bring up %var1 its output is cat

kk

now what i want is that output of %var1 appended to the beginning of many other variables.

so instead of doing a set %catvar2 dog
i do something like set %(%var1 $+ var2) dog

i want that "cat" to be a like a word, that appends to any other word i want within the script, so that by just changing set %var1 cat... to lets say set %var1 gorilla, now the word gorilla has replaced every word "cat" that was originally in the script.

where var1 prefixes var2's name, not its output...

also to have like alias mousecatdog {} instead of typing cat there, its a variable that represents "cat" but still has the same function as if i had actually typed mousecatdog instead of mouse'%var1'dog

hope thats a little more clearer

Joined: Aug 2003
Posts: 37
R
Ameglian cow
Offline
Ameglian cow
R
Joined: Aug 2003
Posts: 37
sorry for the misunderstanding, but you confused the matter by speaking of the "output" of the variable, rather than the variable name, and saying "append" when you meant "prepend."

I have to question whether you really mean to dynamically change variable names in a script based on input? I think you'll be creating a coding and debugging nightmare.

Define this alias:
alias test { set $+(%, $$1, $$2) $$3 | echo $+(%, $$1, $$2) is $eval($+(%, $$1, $$2), 2) }

Demonstrate the behavior is what you intend:
/test label pet dog
/test name 201 cat
//echo labelpet is %labelpet
//echo name201 is %name201

You should be able to extend this for any sort of variable names -- but look at what you have to do: you must add an $eval() to each use of the variable and make the script less readable.

Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
Quote:
i want that "cat" to be a like a word, that appends to any other word i want within the script, so that by just changing set %var1 cat... to lets say set %var1 gorilla, now the word gorilla has replaced every word "cat" that was originally in the script.


I see what you mean. rbhibbs seems to have understood the same thing and he pointed you to the right direction. I'll just explain the same concepts going slowly from dynamic parameters to dynamic variables.

Anyway, what you want can be done in a similar way as my previous (off-topic) example: with $+(). For example, you can have in your script:
Code:
...
echo -a $+(hello,%var1,world)

Whenever this script executes, it will echo "hello<current value of var1>world". Try these to see what I mean (btw, any commands you see from now on that start with double // are meant to be run from an editbox, like Status Window):

//var %var1 = big | echo -a $+(hello,%var1,world) | var %var1 = small | echo -a $+(hello,%var1,world)
(dynamic parameters)

//var %var1 = cho 3 -a | e $+ %var1 hello | var %var1 = cho 4 -a | e $+ %var2 hello
(dynamic commands)

However, there are certain limitations. You can use this technique to dynamically change the parameters of commands/identifiers or even the commands themselves, but you can't use this in alias definitions. Aliases must have static names, eg you can't have something like
Code:
alias %var1 {
  echo -a Hello!
}
With variables, what you want is possible but requires a bit more complex code. Let's take a look at your example %(%var1 $+ var2)

To /set such a variable in a script, you need this:
Code:
set $+(%,%var1,var2) somevalue
To retrieve the value of a variable like this in a script you need
Code:
$eval($+(%,%var1,var2),2)


Ie the script must first construct the variable name. When setting, this is enough. When retrieving the value, however, the newly constructed variable name must be evaluated, and that's where $eval(...,2) comes in. A bit lengthy solution, but works. Here's an example snippet for the 2nd case (retrieving a value):

//var %catfood = fish, %dogfood = meat | var %var1 = dog | echo -a $eval($+(%,%var1,food),2) | var %var1 = cat | echo -a $eval($+(%,%var1,food),2)
(dynamic variable)

Last edited by qwerty; 12/09/03 10:26 AM.

/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
Joined: May 2003
Posts: 161
A
Vogon poet
Offline
Vogon poet
A
Joined: May 2003
Posts: 161
It's less ugly to just use brackets, like %a. [ $+ [ %b ] ] instead of $eval($+(%,a.,%b),2) . The brackets are also a bit faster smile

Joined: Aug 2003
Posts: 37
R
Ameglian cow
Offline
Ameglian cow
R
Joined: Aug 2003
Posts: 37
thanks for enlightening me about alias names -- I was a bit sleepy last night and didn't experiment with creating dynamic aliases, and now you've saved me the effort....

I still wonder if all this effort to create dynamic variable names is worth the maintenance and debugging headache it will create. If the variable name prefix is set WITHIN the script, does this accomplish anything that using a text editor wouldn't? I'm assuming that he's NOT trying to create recursive scripts for such things as lexical and syntactical analyzers or evaluating numerical algorithms.


Joined: Sep 2003
Posts: 5
G
gabaod Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
G
Joined: Sep 2003
Posts: 5
aye i came across the bracket solution last night, havent had time to convert what i have over to that format to test.

And yes, i dont like scripts where you have to find all "word" and replace with another "word" i prefer scripts you just set that as a variable, easier in the long run, headache at first smile

but i think this will work, first heres a working line in a format. my goal is to make bleh a variable name.

%keyse = %blehok [ $+ [ %trignumba ] ]

so i think it would be

set %var bleh
%keyse = %var [ $+ [ ok [ $+ [ %trignumba ] ] ] ]

which i believe will make it %keyse = %blehok# where trignumba = a particular #.

what i was told earlier was to do same thing but without brackets.


Link Copied to Clipboard