| View previous topic :: View next topic |
| Author |
Message |
Fill Halfop
Joined: 18 Jan 2009 Posts: 80
|
Posted: Mon Sep 28, 2009 12:28 pm Post subject: Arrays with strings? |
|
|
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 |
|
 |
Sir_Fz Revered One

Joined: 27 Apr 2003 Posts: 3793 Location: Lebanon
|
Posted: Mon Sep 28, 2009 1:40 pm Post subject: |
|
|
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 |
|
 |
arfer Master

Joined: 26 Nov 2004 Posts: 436 Location: Manchester, UK
|
Posted: Mon Sep 28, 2009 2:03 pm Post subject: |
|
|
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 |
|
 |
Fill Halfop
Joined: 18 Jan 2009 Posts: 80
|
Posted: Mon Sep 28, 2009 2:55 pm Post subject: |
|
|
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 )
See you |
|
| Back to top |
|
 |
Fill Halfop
Joined: 18 Jan 2009 Posts: 80
|
Posted: Tue Sep 29, 2009 1:21 pm Post subject: |
|
|
worked like a charm!!!
Thanks  |
|
| Back to top |
|
 |
|