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 

Arrays with strings?

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


Joined: 18 Jan 2009
Posts: 80

PostPosted: Mon Sep 28, 2009 12:28 pm    Post subject: Arrays with strings? Reply with quote

Hey guys,

I was wondering if there is any kind of arrays where you can use strings. In a normal array, syntax is something like:

Code:

array set <arrayname> {
  Type     Value
}


e.g.

Code:

array set blah {
  prizes        19
  victories     44
  lostgames  6
}


What if I wanted to use strings instead of numbers in the array values?

e.g.

Code:

array set messages {
  #channel 1        "I'm trying to make strings working on arrays"
  #channel2         "This is the message that will be shown on channel2."
}


and so forth and so forth.... I tried to do it like that, but I got an error when I rehashed and loaded the script.

Any suggestions?
Back to top
View user's profile Send private message
Sir_Fz
Revered One


Joined: 27 Apr 2003
Posts: 3793
Location: Lebanon

PostPosted: Mon Sep 28, 2009 1:40 pm    Post subject: Reply with quote

Obviously the code you pasted is going to throw an error since the arguments are not balanced (i.e. #channel 1 ...etc). Try
Code:
array set messages {
 #channel1 "your string here"
 #channel2 "another string here"
}

and it should perfectly work.
_________________
Follow me on GitHub

- Opposing

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


Joined: 26 Nov 2004
Posts: 436
Location: Manchester, UK

PostPosted: Mon Sep 28, 2009 2:03 pm    Post subject: Reply with quote

In Tcl there are only really string values. There are no other data types.

Numbers are strings. They are only treated as numbers when used in the context of a number.

Array element names are strings, as are array element values.

Even a list is a special type of string where any list defining characters are also stored in the string.

I think Tcl is the only language I have used that has this distinct lack of data types. It took me a long time to become comfortable with it.
_________________
I must have had nothing to do
Back to top
View user's profile Send private message
Fill
Halfop


Joined: 18 Jan 2009
Posts: 80

PostPosted: Mon Sep 28, 2009 2:55 pm    Post subject: Reply with quote

sorry I mistyped my post. I wanted to write #channel1 instead of #channel 1

anyway, will try it again. thx for the help (I will be back to say what happened Razz)

See you
Back to top
View user's profile Send private message
Fill
Halfop


Joined: 18 Jan 2009
Posts: 80

PostPosted: Tue Sep 29, 2009 1:21 pm    Post subject: Reply with quote

worked like a charm!!! Laughing Laughing

Thanks Razz
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