<?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/2968" />

	<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>2002-11-14T05:53:19-04:00</updated>

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

		<entry>
		<author><name><![CDATA[ppslim]]></name></author>
		<updated>2002-11-14T05:53:19-04:00</updated>

		<published>2002-11-14T05:53:19-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=13153#p13153</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=13153#p13153"/>
		<title type="html"><![CDATA[random text choose??]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=13153#p13153"><![CDATA[
It's actualy rather simple, and the english exlanation is that was needed, to say what rthe problem was.<br><br>Even for basic programmers, they should know htat simple logic would curb the problem.<br><br>Lets see, there was a Tcl error messages, discribing the error message in plain english. It told you that rand's limit can't be 0. If you get this error, then I am guessing the problem is, it is 0.<br><br>Now you need to look at where this 0 is coming from. seeing as the parameter for the rand command is "[llength $mylist]", then this is the answer.<br><br>Now you can look at why it is returning 0. Well, llength returns the number of elements in a Tcl list. Regardless of the fact the parameter may be a string, if there is text passed to llength, it will return a number above 0.<br><br>From this, we now know that $mylist has no contents. It's value is "".<br><br>Where does the $mylist variable get set<br>[lrange [split $valid($z) "*"] 1 end]<br><br>So from this deduction, we now know, that this command is returning nothing. Seeing as lrange returns a range of items from a list, those items being the second item onwards, we need to know what is being passed to it.<br><br>The split command will send it a list, by splitting a string at the a *. Meaning, if there is no star, no split takes place, and only a list with one item is returned.<br><br>So, if only one items is returned, then lrange wont work, as it wants to return the second item onwards (which don't exist).<br><br>So simply speaking, a check to see how long the list is would surfice. If it's long enough, then let the rand happen, otherwise don't<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=2">ppslim</a> — Thu Nov 14, 2002 5:53 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[Anonymous]]></name></author>
		<updated>2002-11-14T03:32:57-04:00</updated>

		<published>2002-11-14T03:32:57-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=13150#p13150</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=13150#p13150"/>
		<title type="html"><![CDATA[random text choose??]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=13150#p13150"><![CDATA[
i still dont get what you mean   <img class="smilies" src="https://forum.eggheads.org/images/smilies/icon_confused.gif" width="15" height="15" alt=":-?" title="Confused"> <img class="smilies" src="https://forum.eggheads.org/images/smilies/icon_sad.gif" width="15" height="15" alt=":(" title="Sad"> , can you give me more detail or example of the code that I must write to prevent that..pls? coz I'm not smart as you tought  <img class="smilies" src="https://forum.eggheads.org/images/smilies/icon_confused.gif" width="15" height="15" alt=":-?" title="Confused"><p>Statistics: Posted by Guest — Thu Nov 14, 2002 3:32 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[ppslim]]></name></author>
		<updated>2002-11-13T05:30:02-04:00</updated>

		<published>2002-11-13T05:30:02-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=13111#p13111</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=13111#p13111"/>
		<title type="html"><![CDATA[random text choose??]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=13111#p13111"><![CDATA[
If you get this error, it can only mean what it says.<br><br>The random number being generated, is based on 0. Since this number is generated from the length of a list, the length must be 0.<br><br>The only way this is possible, is if $valid($z) contatins no * to seperate the fields, or is blank.<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=2">ppslim</a> — Wed Nov 13, 2002 5:30 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[Anonymous]]></name></author>
		<updated>2002-11-13T04:09:05-04:00</updated>

		<published>2002-11-13T04:09:05-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=13108#p13108</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=13108#p13108"/>
		<title type="html"><![CDATA[random text choose??]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=13108#p13108"><![CDATA[
I try to use:<br><br>set mylist [lrange [split $valid($z) "*"] 1 end]<br>set myrandomtext [lindex $mylist [rand [llength $mylist]]]  <br><br>but the result is:<br><br>[22:48] Tcl error in script for 'timer4':<br>[22:48] random limit must be greater than zero<br><br>in original script, the author used to show all texts like this:<br><br>privmsg $chan "left descript are: sentence 1 ... sentence 2... sentence 3 ...<br><br>and the code is:<br><br>set otherpossibleCounter 0<br>foreach z [array names valid] {<br>if {[lindex $valid($z) 0] == "Nobody"} {<br> if {$otherpossibleCounter != 5} {<br>  append notfound "[lrange $valid($z) 1 end]... "<br>  incr otherpossibleCounter<br> }<br>}<br>}<br><br>I dont want to use append and show all text, I just want to show one of them randomly, but how?<p>Statistics: Posted by Guest — Wed Nov 13, 2002 4:09 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[ppslim]]></name></author>
		<updated>2002-11-12T09:19:25-04:00</updated>

		<published>2002-11-12T09:19:25-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=13087#p13087</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=13087#p13087"/>
		<title type="html"><![CDATA[random text choose??]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=13087#p13087"><![CDATA[
<div class="codebox"><p>Code: </p><pre><code>set myrandomtext [lindex $mylist [expr [rand [llength $mylist]] + 1]] </code></pre></div>RTFM:<br>rand returns a radon dugit between 0 and &lt;limit&gt;-1<br>lindex operates on Tcl lists, which have index's starting from 0<br><br>If you add 1 onto the random digit, it will produce a blank answer on a random basis.<br><br>EG: a 4 item list, where you don't want the first item to be returned.<br><br>Thus, using 4 as the random limit, and adding 1, would somtimes produce number 4, which is not a usable list index.<br><br>To make this script work correctly, change the following to lines<div class="codebox"><p>Code: </p><pre><code>set mylist [split $text "*"] set myrandomtext [lindex $mylist [expr [rand [llength $mylist]] + 1]]  </code></pre></div>to:<div class="codebox"><p>Code: </p><pre><code>set mylist [lrange [split $text "*"] 1 end]set myrandomtext [lindex $mylist [rand [llength $mylist]]]  </code></pre></div><p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=2">ppslim</a> — Tue Nov 12, 2002 9:19 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[cinder]]></name></author>
		<updated>2002-11-12T09:06:42-04:00</updated>

		<published>2002-11-12T09:06:42-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=13086#p13086</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=13086#p13086"/>
		<title type="html"><![CDATA[random text choose??]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=13086#p13086"><![CDATA[
Try:<br><div class="codebox"><p>Code: </p><pre><code>set $filename = "data.txt" // Change to filename of data fileset $fs [open $filename r]gets $fs textclose $fsset mylist [split $text "*"]set myrandomtext [lindex $mylist [expr [rand [llength $mylist]] + 1]] </code></pre></div><p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=1127">cinder</a> — Tue Nov 12, 2002 9:06 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[Anonymous]]></name></author>
		<updated>2002-11-11T04:25:16-04:00</updated>

		<published>2002-11-11T04:25:16-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=13025#p13025</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=13025#p13025"/>
		<title type="html"><![CDATA[random text choose??]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=13025#p13025"><![CDATA[
coz <br><div class="codebox"><p>Code: </p><pre><code>set mylist [join $text] ### Create a proper list assuming a whitespace is a delimiter </code></pre></div>but I dont use set mylist [join $text]<br><br>I just use this code:<br><div class="codebox"><p>Code: </p><pre><code>set myrandomtext [lindex $mylist [expr [rand [llength $mylist]] + 1]] </code></pre></div>as more detail info the file named data is contain data like this:<br><br>data1*text 1*text2*text3<br>data2*text 4*text5*text 6<br>..etc<p>Statistics: Posted by Guest — Mon Nov 11, 2002 4:25 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[Anonymous]]></name></author>
		<updated>2002-11-11T04:16:18-04:00</updated>

		<published>2002-11-11T04:16:18-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=13024#p13024</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=13024#p13024"/>
		<title type="html"><![CDATA[random text choose??]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=13024#p13024"><![CDATA[
i use : set myrandomtext [lindex $mylist [expr [rand [llength $mylist]] + 1]] . and it works. thanks<br><br>but there's something bugging me because<br><br>if my data filename is contain text like:<br><br>data1*a text1*b text2*text3<br><br>my eggdrop is only show 'a' and not 'a text1'<br><br>and also sometimes dont show any<br><br><br>can you help me find the wrong? thx I really apreciate it<p>Statistics: Posted by Guest — Mon Nov 11, 2002 4:16 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[strikelight]]></name></author>
		<updated>2002-11-07T15:40:44-04:00</updated>

		<published>2002-11-07T15:40:44-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=12930#p12930</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=12930#p12930"/>
		<title type="html"><![CDATA[random text choose??]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=12930#p12930"><![CDATA[
<blockquote class="uncited"><div>Assuming variable $text contains your line:<br><br>set mylist [join $text] ### Create a proper list assuming a whitespace is a delimiter<br>set myrandomtext [lindex $mylist [expr [rand [llength $mylist]] + 1]]<br><br>The second line looks a bit scary because it need's to get rid of data1 and consider only text1 text2 ect...</div></blockquote>"join" will create a string from what is supposed to be a list..<br>What I believe you want is:<br><div class="codebox"><p>Code: </p><pre><code>set mylist [split $text]</code></pre></div>But since he provided an example line, something like:<br>data1*text1*text2*text3<br><br>It should be:<div class="codebox"><p>Code: </p><pre><code>set mylist [split $text "*"]</code></pre></div><p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=2005">strikelight</a> — Thu Nov 07, 2002 3:40 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[darko``]]></name></author>
		<updated>2002-11-06T14:18:51-04:00</updated>

		<published>2002-11-06T14:18:51-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=12897#p12897</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=12897#p12897"/>
		<title type="html"><![CDATA[random text choose??]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=12897#p12897"><![CDATA[
Assuming variable $text contains your line:<br><br>set mylist [join $text] ### Create a proper list assuming a whitespace is a delimiter<br>set myrandomtext [lindex $mylist [expr [rand [llength $mylist]] + 1]]<br><br>The second line looks a bit scary because it need's to get rid of data1 and consider only text1 text2 ect...<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=1881">darko``</a> — Wed Nov 06, 2002 2:18 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[Anonymous]]></name></author>
		<updated>2002-11-06T04:53:01-04:00</updated>

		<published>2002-11-06T04:53:01-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=12882#p12882</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=12882#p12882"/>
		<title type="html"><![CDATA[random text choose??]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=12882#p12882"><![CDATA[
if I have a file named data and contain text like this:<br><br>data1*text1*text2*text3<br><br>and then I want to execute that file in a tcl<br>what should I type in that tcl for bot saying one of that text (text1, text2, text3) randomly??<br><br>thx<p>Statistics: Posted by Guest — Wed Nov 06, 2002 4:53 am</p><hr />
]]></content>
	</entry>
	</feed>
