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.
Help for those learning Tcl or writing their own scripts.
-
Fill
- Halfop
- Posts: 80
- Joined: Sun Jan 18, 2009 6:08 pm
Post
by Fill »
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: Select all
array set <arrayname> {
Type Value
}
e.g.
Code: Select all
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: Select all
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?
-
Sir_Fz
- Revered One
- Posts: 3794
- Joined: Sun Apr 27, 2003 3:10 pm
- Location: Lebanon
-
Contact:
Post
by Sir_Fz »
Obviously the code you pasted is going to throw an error since the arguments are not balanced (i.e.
#channel 1 ...etc). Try
Code: Select all
array set messages {
#channel1 "your string here"
#channel2 "another string here"
}
and it should perfectly work.
-
arfer
- Master
- Posts: 436
- Joined: Fri Nov 26, 2004 8:45 pm
- Location: Manchester, UK
Post
by arfer »
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
-
Fill
- Halfop
- Posts: 80
- Joined: Sun Jan 18, 2009 6:08 pm
Post
by Fill »
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
-
Fill
- Halfop
- Posts: 80
- Joined: Sun Jan 18, 2009 6:08 pm
Post
by Fill »
worked like a charm!!!
Thanks