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.

[SOLVED] help passing $data in array

Help for those learning Tcl or writing their own scripts.
Post Reply
d
doggo
Halfop
Posts: 97
Joined: Tue Jan 05, 2010 7:53 am
Contact:

[SOLVED] help passing $data in array

Post by doggo »

heres the proc

Code: Select all

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: Select all

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 :P

the array works grat for the colours part, but this is what i cant get my head around..

channel output

Code: Select all

[$data] [$data] http://someurl.net
i bet its a real simple solution too, but i cant figure it out :cry:
Last edited by doggo on Fri Sep 07, 2012 9:02 am, edited 1 time in total.
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

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: Select all

...
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.
Last edited by nml375 on Fri Sep 07, 2012 1:27 pm, edited 1 time in total.
NML_375
d
doggo
Halfop
Posts: 97
Joined: Tue Jan 05, 2010 7:53 am
Contact:

Post by doggo »

cheers nml375 all works great now :D
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

Code: Select all

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. ^_~
Post Reply