<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-gb">
	<link rel="self" type="application/atom+xml" href="https://forum.eggheads.org/app.php/feed/topic/14246" />

	<title>egghelp/eggheads community</title>
	<subtitle>Discussion of eggdrop bots, shell accounts and tcl scripts.</subtitle>
	<link href="https://forum.eggheads.org/index.php" />
	<updated>2007-11-10T06:22:52-04:00</updated>

	<author><name><![CDATA[egghelp/eggheads community]]></name></author>
	<id>https://forum.eggheads.org/app.php/feed/topic/14246</id>

		<entry>
		<author><name><![CDATA[BCyo+8C4]]></name></author>
		<updated>2007-11-10T06:22:52-04:00</updated>

		<published>2007-11-10T06:22:52-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=77672#p77672</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=77672#p77672"/>
		<title type="html"><![CDATA[selecting a random item from an array]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=77672#p77672"><![CDATA[
thanks guys. I had already tried that method before but due to an error later in the script the $tnick wouldn't be picked up (strangely it was when I had set it manually, that's why I didn't figure it at first)<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=8166">BCyo+8C4</a> — Sat Nov 10, 2007 6:22 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[r0t3n]]></name></author>
		<updated>2007-11-09T15:35:47-04:00</updated>

		<published>2007-11-09T15:35:47-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=77548#p77548</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=77548#p77548"/>
		<title type="html"><![CDATA[selecting a random item from an array]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=77548#p77548"><![CDATA[
a little error there Sir_Fz, forgot the rand...<br><div class="codebox"><p>Code: </p><pre><code>set playersList [array names players]set tnick [lindex $playersList [rand [llength $playersList]]]</code></pre></div>or in one line:<br><div class="codebox"><p>Code: </p><pre><code>set tnick [lindex [array names players] [rand [array names players]]]</code></pre></div><p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=6300">r0t3n</a> — Fri Nov 09, 2007 3:35 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[Sir_Fz]]></name></author>
		<updated>2007-11-09T20:15:42-04:00</updated>

		<published>2007-11-08T18:16:42-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=77536#p77536</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=77536#p77536"/>
		<title type="html"><![CDATA[selecting a random item from an array]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=77536#p77536"><![CDATA[
<div class="codebox"><p>Code: </p><pre><code>set playersList [array names players]set tnick [lindex $playersList [rand [llength $playersList]]]</code></pre></div>Edit: Thanks Tosser^^<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=3085">Sir_Fz</a> — Thu Nov 08, 2007 6:16 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[rosc2112]]></name></author>
		<updated>2007-11-08T16:22:45-04:00</updated>

		<published>2007-11-08T16:22:45-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=77530#p77530</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=77530#p77530"/>
		<title type="html"><![CDATA[selecting a random item from an array]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=77530#p77530"><![CDATA[
In other words, get the array names into a list variable, then pull the random name you want, then use that name to get the data from the array! <img class="smilies" src="https://forum.eggheads.org/images/smilies/icon_smile.gif" width="15" height="15" alt=":)" title="Smile"><p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=7395">rosc2112</a> — Thu Nov 08, 2007 4:22 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[BCyo+8C4]]></name></author>
		<updated>2007-11-08T13:49:49-04:00</updated>

		<published>2007-11-08T13:49:49-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=77528#p77528</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=77528#p77528"/>
		<title type="html"><![CDATA[selecting a random item from an array]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=77528#p77528"><![CDATA[
seriously, I already played ages with those commands and couldn't figure it out. if you want to help me please do so, but don't make me look like someone who doesn't rtfm!<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=8166">BCyo+8C4</a> — Thu Nov 08, 2007 1:49 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[nml375]]></name></author>
		<updated>2007-11-08T13:39:24-04:00</updated>

		<published>2007-11-08T13:39:24-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=77527#p77527</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=77527#p77527"/>
		<title type="html"><![CDATA[selecting a random item from an array]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=77527#p77527"><![CDATA[
Have a second look at "array names", and you should see that it returns a list of keys in the array. That on it's own is quite unusable as a command.<br>But, since you now got a list of names, make use of commands such as lindex to actually select an item from that list...<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=8052">nml375</a> — Thu Nov 08, 2007 1:39 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[BCyo+8C4]]></name></author>
		<updated>2007-11-08T13:33:56-04:00</updated>

		<published>2007-11-08T13:33:56-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=77526#p77526</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=77526#p77526"/>
		<title type="html"><![CDATA[selecting a random item from an array]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=77526#p77526"><![CDATA[
I tried various array commands as well, like this one:<div class="codebox"><p>Code: </p><pre><code>set tnick [[array names $players] [rand [array size $players]]]</code></pre></div>I spent about 1,5h trying to figure this out already, the help files don't help me with this anymore. So could you please tell me how to do it?<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=8166">BCyo+8C4</a> — Thu Nov 08, 2007 1:33 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[nml375]]></name></author>
		<updated>2007-11-08T13:10:47-04:00</updated>

		<published>2007-11-08T13:10:47-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=77525#p77525</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=77525#p77525"/>
		<title type="html"><![CDATA[selecting a random item from an array]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=77525#p77525"><![CDATA[
players is an array, not a flat variable containing a list... big difference there..<br>The command you need to use with arrays is called <a href="http://www.tcl.tk/man/tcl8.4/TclCmd/array.htm" class="postlink">array</a>.<br><a href="http://www.tcl.tk/man/tcl8.4/TclCmd/llength.htm" class="postlink">llength</a> only operates on lists, same goes for <a href="http://www.tcl.tk/man/tcl8.4/TclCmd/lindex.htm" class="postlink">lindex</a>.<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=8052">nml375</a> — Thu Nov 08, 2007 1:10 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[BCyo+8C4]]></name></author>
		<updated>2007-11-08T12:34:01-04:00</updated>

		<published>2007-11-08T12:34:01-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=77523#p77523</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=77523#p77523"/>
		<title type="html"><![CDATA[selecting a random item from an array]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=77523#p77523"><![CDATA[
Hi,<br>I've got an array that's populated using <div class="codebox"><p>Code: </p><pre><code>set players($nick) 1</code></pre></div>, the "1" there is increased depending on certain events later.<br><br>Now my problem: I want to select a random item (= nick) from the $players array, but I can't figure out how to do it.<div class="codebox"><p>Code: </p><pre><code>set tnick [lindex $players [rand [llength $players]]]</code></pre></div>just tells me later on that <em class="text-italics">can't read "tnick": no such variable</em> and I have no idea what code I'd have to use instead.<br><br>Thx for any help.<br><br>PS: I only need a random nick from the array, not the number behind it.<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=8166">BCyo+8C4</a> — Thu Nov 08, 2007 12:34 pm</p><hr />
]]></content>
	</entry>
	</feed>
