write :
for i := 0 to my_array.items.count -1 do
my_memo.lines.add(my_array.item[i])
get :
for i := 0 to my_memo.lines.count -1 do
my_array.item[i] := memo1.lines[i]
The array isn't myvar(1) myvar(2) but myvar(word) myvar(anotherword) and so on.
I'd like to dump this var into a txt file and if the bot restarts it should write the var based onto the data in this txt.
ppslim, one problem with your code: in read_array you're passing the result of [read] to uplevel to be evaluated (since you used quotes). Maybe a better way is to use upvar?
ppslim give me some credit! I think you misunderstood what I said. Uplevel works just like eval, right? So it's not very safe to read in text and simply eval it. If there is a stray line with [blah blah] it will try to execute it. Now, if the person *only* uses write_array to write the file, it's not too bad, because it will escape those characters.
That said, I just realized the code doesn't even work. The 'array set' command expects a list as a single variable, e.g.
. The code as stated, since it evaluates the *result* of [read] rather than the [read] itself, will make each thing a separate argument rather than a list element. This will call the command with too many arguments.
Perhaps I have been away too long if you've forgotten to put such things in a
construct rather than just quotes :) This is the same sort of problem that occurs when people say utimer "putserv $blah" rather than utimer [list putserv $blah].
Anyway, it's easier and more efficient to use the upvar command rather than have tcl create all these lists.
In tcl, there are no multidimensional arrays. When you say blah(word1,word2) that is actually a single entry called "word1,word2", which is a perfectly valid name. If you say blah(word1) it will not return a new array (as a real multidimensional array would).
Anyway, I'll go ahead and update this code a bit, this should work, although I haven't tested it: