| View previous topic :: View next topic |
| Author |
Message |
doggo Halfop
Joined: 05 Jan 2010 Posts: 97
|
Posted: Fri Aug 24, 2012 10:56 am Post subject: [SOLVED] help passing $data in array |
|
|
heres the proc
| Code: | proc omgwtfnzb:brace { c data } {
set iscat $c
array set cats {
1 "\00307\[$data\]\017"
2 "\00307\[$data\]\017"
3 "\00306\[$data\]\017"
4 "\00307\[$data\]\017"
5 "\00307\[$data\]\017"
6 "\00307\[$data\]\017"
7 "\00306\[$data\]\017"
8 "\00306\[$data\]\017"
9 "\00303\[$data\]\017"
10 "\00303\[$data\]\017"
11 "\00303\[$data\]\017"
12 "\00302\[$data\]\017"
13 "\00302\[$data\]\017"
14 "\00302\[$data\]\017"
15 "\00308\[$data\]\017"
16 "\00308\[$data\]\017"
17 "\00308\[$data\]\017"
18 "\00308\[$data\]\017"
19 "\00311\[$data\]\017"
20 "\00311\[$data\]\017"
21 "\00311\[$data\]\017"
22 "\00306\[$data\]\017"
23 "\00313\[$data\]\017"
}
foreach { catnum catagorey } [array get cats] {
if { $iscat == $catnum } {
set return_cat $catagorey
break
}
}
return $return_cat
} |
i use it in another proc like this
| Code: | | puthelp "privmsg $info_chan :[omgwtfnzb:brace $x2 $x5] [omgwtfnzb:brace $x2 $x6] $info_baseurl$x1" |
x2 is $c and $x5, $x6 make up $data, the problem im having is when the proc is trigered it returns the word $data, and not the actual data.. if you get what i mean
the array works grat for the colours part, but this is what i cant get my head around..
channel output
| Code: | | [$data] [$data] http://someurl.net |
i bet its a real simple solution too, but i cant figure it out  _________________ NON geeky!! http://gotcode4u.com/
Last edited by doggo on Fri Sep 07, 2012 9:02 am; edited 1 time in total |
|
| Back to top |
|
 |
nml375 Revered One
Joined: 04 Aug 2006 Posts: 2857
|
Posted: Fri Aug 24, 2012 12:25 pm Post subject: |
|
|
In this case, you have to explicitly enforce variable substitutions.
There are a few ways to do this, though I believe this is the most secure approach:
| Code: | ...
foreach {catnum category} [array get cats] {
if {$iscat == $catnum} {
return [subst -nobackslashes -nocommands $category]
}
} |
This way, we enforce the variable-substitution once we've extracted the correct template, and we explicitly block command and backslash substitutions. _________________ NML_375, idling at #eggdrop@IrcNET
Last edited by nml375 on Fri Sep 07, 2012 1:27 pm; edited 1 time in total |
|
| Back to top |
|
 |
doggo Halfop
Joined: 05 Jan 2010 Posts: 97
|
Posted: Fri Sep 07, 2012 9:01 am Post subject: |
|
|
cheers nml375 all works great now  _________________ NON geeky!! http://gotcode4u.com/ |
|
| Back to top |
|
 |
speechles Revered One

Joined: 26 Aug 2006 Posts: 1398 Location: emerald triangle, california (coastal redwoods)
|
Posted: Fri Sep 07, 2012 3:21 pm Post subject: |
|
|
| Code: | proc omgwtfnzb:brace { c data } {
# array of colors
array set cats {
1 "\00307"
2 "\00307"
3 "\00306"
4 "\00307"
5 "\00307"
6 "\00307"
7 "\00306"
8 "\00306"
9 "\00303"
10 "\00303"
11 "\00303"
12 "\00302"
13 "\00302"
14 "\00302"
15 "\00308"
16 "\00308"
17 "\00308"
18 "\00308"
19 "\00311"
20 "\00311"
21 "\00311"
22 "\00306"
23 "\00313"
}
# Does the category exist?
if {[info exists cats($c)]} {
# yes - return formatted data
return "$cats($c)\[$data\]\017"
} else {
# no - do nothing
}
} |
You only need to keep the part that changes inside your array. The rest can be tacked on during your return. This is a much simpler way to do it. ^_~ _________________ speechles' eggdrop tcl archive |
|
| Back to top |
|
 |
|