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 

Question about an array

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


Joined: 21 Jan 2006
Posts: 155

PostPosted: Wed Jun 28, 2006 4:10 pm    Post subject: Question about an array Reply with quote

Hello!
I have a question about an array. In one of my scripts I have this here:
Code:
set reset [lrange [split $arg] 0 2]
if {[string match -nocase {text 1} $reset] || [string match -nocase {text 2} $reset]} {set case 1}

But now I want to replace the "text 1" and "text 2" with an array. So I made this:
Code:

set case 0
set reset [lrange [split $arg] 0 2
set texts {
"text 1"
"text 2"
"text 3"
"text 4"
}

set texts2 {
"text 5"
"text 6"
"text 7"
}
  foreach text $texts {
  if {[string match -nocase $text $reset]} {set case 1}
  }
  foreach text2 $texts2 {
  if {[string match -nocase $text2 $reset]} {set case 2}
  } 

But it don't set the variable "case" to 1 or 2. There must be something wrong with the foreach statements. Can anybody correct it for me?
Back to top
View user's profile Send private message
krimson
Halfop


Joined: 19 Apr 2006
Posts: 86

PostPosted: Wed Jun 28, 2006 4:27 pm    Post subject: Reply with quote

try using
Code:
foreach text [split $texts \n] {
  if {[string match -nocase $text $reset]} {set case 1}
}


it should work
Back to top
View user's profile Send private message Send e-mail
darton
Op


Joined: 21 Jan 2006
Posts: 155

PostPosted: Wed Jun 28, 2006 4:40 pm    Post subject: Reply with quote

No, it doesn't.
Back to top
View user's profile Send private message
Sir_Fz
Revered One


Joined: 27 Apr 2003
Posts: 3793
Location: Lebanon

PostPosted: Wed Jun 28, 2006 7:20 pm    Post subject: Reply with quote

Quote:
set reset [lrange [split $arg] 0 2

You need to close the bracket.
Code:
set reset [lrange [split $arg] 0 2]

_________________
Follow me on GitHub

- Opposing

Public Tcl scripts
Back to top
View user's profile Send private message Visit poster's website
darton
Op


Joined: 21 Jan 2006
Posts: 155

PostPosted: Thu Jun 29, 2006 9:35 am    Post subject: Reply with quote

Of course I closed the bracket, but forgot to post it here. I give you now my whole script so that you can see what is wrong.
Code:
bind pubm - * reset:flag
proc reset:flag {nick uhost hand chan arg} {
  set reset [lrange [split $arg] 0 2]
  set reset [stripcodes bcruag $reset] 
  set case 0

  set 3er_maps {
  "C&C_Under.mix"
  "C&C_Hourglass.mix"
  }
  foreach map3 $3er_maps {
  if {[string match -nocase {Loading Level $map3} $reset]} {set case 1}
  }

  if {$case == 1} {
   putquick "PRIVMSG $chan :..."
}

If somebody in the channel writes "Loading level C&C_Under.mix" the variable "case" should be set to 1, but that does not happen.
Back to top
View user's profile Send private message
spock
Master


Joined: 12 Dec 2002
Posts: 319

PostPosted: Thu Jun 29, 2006 10:29 am    Post subject: Reply with quote

try
Code:
if {[string match -nocase "Loading Level $map3" $reset]}

and maybe
Code:
set reset [join [lrange [split $arg] 0 2]]

_________________
photon?
Back to top
View user's profile Send private message
darton
Op


Joined: 21 Jan 2006
Posts: 155

PostPosted: Thu Jun 29, 2006 10:49 am    Post subject: Reply with quote

No, that doesn't work, too.
Back to top
View user's profile Send private message
spock
Master


Joined: 12 Dec 2002
Posts: 319

PostPosted: Thu Jun 29, 2006 11:03 am    Post subject: Reply with quote

Yes, that does work, here. Smile

edit: this works for me
Code:
bind pubm - * reset:flag
proc reset:flag {nick uhost hand chan arg} {
  set reset [join [lrange [split $arg] 0 2]]
# set reset [stripcodes bcruag $reset]
  set case 0
  set 3er_maps {
    "C&C_Under.mix"
    "C&C_Hourglass.mix"
  }
  foreach map3 $3er_maps {
    if {[string match -nocase "Loading Level $map3" $reset]} {set case 1}
  }
  if {$case == 1} {
   putquick "PRIVMSG $chan :..."
  }
}

_________________
photon?
Back to top
View user's profile Send private message
darton
Op


Joined: 21 Jan 2006
Posts: 155

PostPosted: Thu Jun 29, 2006 11:18 am    Post subject: Reply with quote

OK, thank you, it works for me too now.
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