egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

[SOLVED] help passing $data in array

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
doggo
Halfop


Joined: 05 Jan 2010
Posts: 97

PostPosted: Fri Aug 24, 2012 10:56 am    Post subject: [SOLVED] help passing $data in array Reply with quote

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 Razz

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 Crying or Very sad
_________________
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
View user's profile Send private message Visit poster's website
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Fri Aug 24, 2012 12:25 pm    Post subject: Reply with quote

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
View user's profile Send private message
doggo
Halfop


Joined: 05 Jan 2010
Posts: 97

PostPosted: Fri Sep 07, 2012 9:01 am    Post subject: Reply with quote

cheers nml375 all works great now Very Happy
_________________
NON geeky!! http://gotcode4u.com/
Back to top
View user's profile Send private message Visit poster's website
speechles
Revered One


Joined: 26 Aug 2006
Posts: 1398
Location: emerald triangle, california (coastal redwoods)

PostPosted: Fri Sep 07, 2012 3:21 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber