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

	<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>2016-05-03T20:10:42-04:00</updated>

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

		<entry>
		<author><name><![CDATA[Landslyde]]></name></author>
		<updated>2016-05-03T20:10:42-04:00</updated>

		<published>2016-05-03T20:10:42-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=104962#p104962</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=104962#p104962"/>
		<title type="html"><![CDATA[Array producing crazy indexes]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=104962#p104962"><![CDATA[
willyw and caesar:<br><br>Thank you both for your input. I get what you said, all but the $swap / split stuff. I'll work with this and see what I can do. Really appreciated.<br><br>And sorry for the pate response. I just set my IRC network back up and have been going hard at it there.<br><br>Thanks again <img class="smilies" src="https://forum.eggheads.org/images/smilies/icon_biggrin.gif" width="15" height="15" alt=":D" title="Very Happy"><p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=12386">Landslyde</a> — Tue May 03, 2016 8:10 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[willyw]]></name></author>
		<updated>2016-04-28T10:29:33-04:00</updated>

		<published>2016-04-28T10:29:33-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=104948#p104948</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=104948#p104948"/>
		<title type="html"><![CDATA[Array producing crazy indexes]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=104948#p104948"><![CDATA[
<blockquote class="uncited"><div>Since the <em class="text-italics">$swap</em> was already a list...</div></blockquote>It sure looked like it to me.   <img class="smilies" src="https://forum.eggheads.org/images/smilies/icon_smile.gif" width="15" height="15" alt=":)" title="Smile"><blockquote class="uncited"><div>The only notable difference between the <em class="text-italics">for</em> loop and <em class="text-italics">while</em> loop lays in the number of lines you use, else you will get the same results. ...</div></blockquote>Good.<blockquote class="uncited"><div>As a rule of thumb I tend to stay away from <em class="text-italics">while</em> loops cos if you screw up something, like let's say you forget that increment of the <em class="text-italics">x</em> variable, it has the potential to loop indefinitely and don't want that. <img class="smilies" src="https://forum.eggheads.org/images/smilies/icon_smile.gif" width="15" height="15" alt=":)" title="Smile"></div></blockquote>I don't forget it, but I still manage to screw it up somehow on the first draft.   <img class="smilies" src="https://forum.eggheads.org/images/smilies/icon_biggrin.gif" width="15" height="15" alt=":D" title="Very Happy"><blockquote class="uncited"><div>The <em class="text-italics">for</em> loop has all the stuff defined right away in the same line and it's next to impossible to screw up something to make it run indefinitely.  <img class="smilies" src="https://forum.eggheads.org/images/smilies/icon_razz.gif" width="15" height="15" alt=":P" title="Razz"></div></blockquote>Next time I need something like this, and after these few posts here now, maybe I'll remember to utilize the for loop.<br><br>Thanks.<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=10420">willyw</a> — Thu Apr 28, 2016 10:29 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[caesar]]></name></author>
		<updated>2016-04-28T10:16:12-04:00</updated>

		<published>2016-04-28T10:16:12-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=104947#p104947</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=104947#p104947"/>
		<title type="html"><![CDATA[Array producing crazy indexes]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=104947#p104947"><![CDATA[
Since the <em class="text-italics">$swap</em> was already a list the split wasn't needed. Thanks for pointing that out. Fixed the above code. <img class="smilies" src="https://forum.eggheads.org/images/smilies/icon_smile.gif" width="15" height="15" alt=":)" title="Smile"><br><br>The only notable difference between the <em class="text-italics">for</em> loop and <em class="text-italics">while</em> loop lays in the number of lines you use, else you will get the same results. For example with a <em class="text-italics">while</em> loop the <em class="text-italics">dice:roll</em> function would be:<div class="codebox"><p>Code: </p><pre><code>proc dice:roll {count} { set x 0while {$x&lt;$count} {lappend roll [expr [rand 6] + 1] incr x}return $roll}</code></pre></div>As a rule of thumb I tend to stay away from <em class="text-italics">while</em> loops cos if you screw up something, like let's say you forget that increment of the <em class="text-italics">x</em> variable, it has the potential to loop indefinitely and don't want that. <img class="smilies" src="https://forum.eggheads.org/images/smilies/icon_smile.gif" width="15" height="15" alt=":)" title="Smile"><br><br>The <em class="text-italics">for</em> loop has all the stuff defined right away in the same line and it's next to impossible to screw up something to make it run indefinitely.  <img class="smilies" src="https://forum.eggheads.org/images/smilies/icon_razz.gif" width="15" height="15" alt=":P" title="Razz"><p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=187">caesar</a> — Thu Apr 28, 2016 10:16 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[willyw]]></name></author>
		<updated>2016-04-28T09:58:27-04:00</updated>

		<published>2016-04-28T09:58:27-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=104946#p104946</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=104946#p104946"/>
		<title type="html"><![CDATA[Array producing crazy indexes]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=104946#p104946"><![CDATA[
<blockquote class="uncited"><div>Ah! Right. Power of habit. <img class="smilies" src="https://forum.eggheads.org/images/smilies/icon_rolleyes.gif" width="15" height="15" alt=":roll:" title="Rolling Eyes"></div></blockquote>ahh..<br>I was doubting myself.  I looked it, and again, and again...   <br><br>Finally, I just had to ask.    <img class="smilies" src="https://forum.eggheads.org/images/smilies/icon_smile.gif" width="15" height="15" alt=":)" title="Smile"><br><br><br>By the way:<br>I forget about for loops.   I'm glad you posted that.<br><br>Sometimes - not often - I will use a while loop.   <br>With just a quick overview of both, it seems like in many cases, either could be used.<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=10420">willyw</a> — Thu Apr 28, 2016 9:58 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[caesar]]></name></author>
		<updated>2016-04-28T09:36:48-04:00</updated>

		<published>2016-04-28T09:36:48-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=104945#p104945</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=104945#p104945"/>
		<title type="html"><![CDATA[Array producing crazy indexes]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=104945#p104945"><![CDATA[
Ah! Right. Power of habit. <img class="smilies" src="https://forum.eggheads.org/images/smilies/icon_rolleyes.gif" width="15" height="15" alt=":roll:" title="Rolling Eyes"><p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=187">caesar</a> — Thu Apr 28, 2016 9:36 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[willyw]]></name></author>
		<updated>2016-04-28T05:33:01-04:00</updated>

		<published>2016-04-28T05:33:01-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=104942#p104942</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=104942#p104942"/>
		<title type="html"><![CDATA[Array producing crazy indexes]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=104942#p104942"><![CDATA[
<blockquote class="uncited"><div>...<br> That's why having the indexes be static as set in the array is important.<br><br>...<br> That's why having the indexes static and not rearranging themselves is necessary.<br><br>...</div></blockquote>Or, is it just necessary to be able to find them somehow?   Maybe it would be better to ask that.<br>This is assuming you are really wanting to work with arrays and learn what they can do.  This is not to say that an array is the best tool for your present job.<br><br>I don't think that an array works that way - held in position.  (Perhaps caesar and nml375 will comment)<br>When this happens, it can be time to find another way with TCL, to do what you are envisioning.   See caesar's code.  <br><br>If mastering arrays right now is not the main focus, but finding a way to roll your dice is, then spend some time experimenting with his code, piece by piece. Figure out how he is doing it.  It is interesting.<br>I was thinking of lists, but had not gone further.<br><br>caesar:<br>set swap [split $swap] <br>Just curious - why split?  Isn't $swap already a list?<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=10420">willyw</a> — Thu Apr 28, 2016 5:33 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[caesar]]></name></author>
		<updated>2016-04-28T10:19:55-04:00</updated>

		<published>2016-04-28T01:45:03-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=104941#p104941</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=104941#p104941"/>
		<title type="html"><![CDATA[Array producing crazy indexes]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=104941#p104941"><![CDATA[
Instead of all this:<div class="codebox"><p>Code: </p><pre><code>set die1 [lindex $dice [rand [llength $dice]]]set die2 [lindex $dice [rand [llength $dice]]]set die3 [lindex $dice [rand [llength $dice]]]set die4 [lindex $dice [rand [llength $dice]]]set die5 [lindex $dice [rand [llength $dice]]]set die6 [lindex $dice [rand [llength $dice]]]</code></pre></div>I would use this code:<div class="codebox"><p>Code: </p><pre><code>proc dice:roll {count} {for {set x 0} {$x&lt;$count} {incr x} {lappend roll [expr [rand 6] + 1]}return $roll}</code></pre></div>to get a roll of 6 dices then:<div class="codebox"><p>Code: </p><pre><code>set roll [dice:roll 6]</code></pre></div>Now, if taking your example where you got a list of 3 positions to swap and want to generate 3 new rolls, we have the positions stored in a variable, for example:<div class="codebox"><p>Code: </p><pre><code>set pos [list 0 2 3]</code></pre></div>and to generate 3 or an unknown number of rolls:<div class="codebox"><p>Code: </p><pre><code>set swap [dice:roll [llength $pos]]</code></pre></div>and then to do the actual swap use this code:<div class="codebox"><p>Code: </p><pre><code>proc dice:swap {pos roll swap} {set count [llength $pos]for {set x 0} {$x&lt;$count} {incr x} {set ele [lindex $pos $x]set roll [lreplace $roll $ele $ele [lindex $swap $x]]}return $roll}</code></pre></div>and call it:<div class="codebox"><p>Code: </p><pre><code>set newRoll [dice:swap $pos $roll $swap]</code></pre></div>From here do whatever you want with <em class="text-italics">$newRoll</em> as is a list with 6 rolls that have been changed in the positions you asked for.<br><br>And here's the result:<div class="codebox"><p>Code: </p><pre><code>% set roll [list 2 5 4 6 5 5]2 5 4 6 5 5% set pos [list 0 2 3]0 2 3% set swap [list 4 6 2]4 6 2% dice:swap $pos $roll $swap4 5 6 2 5 5</code></pre></div>Hope this helps. <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=187">caesar</a> — Thu Apr 28, 2016 1:45 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[Landslyde]]></name></author>
		<updated>2016-04-28T00:35:12-04:00</updated>

		<published>2016-04-28T00:35:12-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=104940#p104940</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=104940#p104940"/>
		<title type="html"><![CDATA[Array producing crazy indexes]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=104940#p104940"><![CDATA[
Thank you for the link. It has a lot more info on arrays. I think I'll be able to sort out what I need, which is allowing the user to select the dice they want to re-roll. That's why having the indexes be static as set in the array is important.<br><br>Say the roll is:  2  5  4  6  5  5<br><br>They wld want to keep the three 5s and re-roll  the 2 4 6. Set in the array, those wld be indexes 0, 2, and 3. Then I'd unset those in the array and append the re-roll to the three 5s. That's why having the indexes static and not rearranging themselves is necessary.<br><br>But thank you for the link, willyw. I'll study what they have there and see what I can come up with.<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=12386">Landslyde</a> — Thu Apr 28, 2016 12:35 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[willyw]]></name></author>
		<updated>2016-04-27T21:55:55-04:00</updated>

		<published>2016-04-27T21:55:55-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=104939#p104939</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=104939#p104939"/>
		<title type="html"><![CDATA[Re: Array producing crazy indexes]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=104939#p104939"><![CDATA[
<blockquote class="uncited"><div>...<br>putquick "$fPRVMSG $fChan :The rolled numbers are: [array get arolled]"<br>....</div></blockquote>See:<br><a href="http://www.tcl.tk/man/tcl8.5/TclCmd/array.htm#M8" class="postlink">http://www.tcl.tk/man/tcl8.5/TclCmd/array.htm#M8</a><br><br>"... The order of the pairs is undefined...."<br><br>Is that it?<br><br>I hope this helps.<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=10420">willyw</a> — Wed Apr 27, 2016 9:55 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[Landslyde]]></name></author>
		<updated>2016-04-27T21:20:41-04:00</updated>

		<published>2016-04-27T21:20:41-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=104938#p104938</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=104938#p104938"/>
		<title type="html"><![CDATA[Array producing crazy indexes]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=104938#p104938"><![CDATA[
So this is my first-ever script. It's a dice game I use to play growing up way back in the stone age. The dice array is acting weird though. The array information I'm using is from <a href="http://www.tcl.tk/man/tcl8.5/tutorial/Tcl22.html" class="postlink">http://www.tcl.tk/man/tcl8.5/tutorial/Tcl22.html</a>.<br><div class="codebox"><p>Code: </p><pre><code>set dice{ "1""2" "3" "4""5" "6"}proc roll:dice {nick host handle chan arg} { global dice fPRVMSG fChan numbersset die1 [lindex $dice [rand [llength $dice]]]set die2 [lindex $dice [rand [llength $dice]]]set die3 [lindex $dice [rand [llength $dice]]]set die4 [lindex $dice [rand [llength $dice]]]set die5 [lindex $dice [rand [llength $dice]]]set die6 [lindex $dice [rand [llength $dice]]]set rolled [list $die1 $die2 $die3 $die4 $die5 $die6]array set arolled [list $die1 $die2 $die3 $die4 $die5 $die6]putquick "$fPRVMSG $chan :$nick rolls  \002\0030,4  $die1  \003 \002\0030,4  $die2  \003  \002\0030,4  $die3  \003  \002\0030,4  $die4  \003  \002\0030,4  $die5  \003  \002\0030,4  $die6  \003"putquick "$fPRVMSG $fChan :The rolled numbers are: [array get arolled]"putquick "$fPRVMSG $fChan :Dice 3 and 5 were: $arolled(2) and $arolled(4)"}</code></pre></div>Following the three outputs, this is what I get from my bot:<br><div class="codebox"><p>Code: </p><pre><code>[19:54:30] &lt;@Slyde&gt; .roll[19:54:31] &lt;Shianne&gt; Slyde rolls    4     2      6      5      2      3  [19:54:32] &lt;Shianne&gt; The rolled numbers are: 4 2 2 3 6 5[19:54:32] &lt;Shianne&gt; Dice 3 and 5 were: 3 and 2</code></pre></div>The indexes are off from the way I stored them in the last two outputs. But, like I said, this is my first tcl script. So maybe I'm not using the arrays the right way. Will someone please tell me what I'm doing wrong? Thanks.<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=12386">Landslyde</a> — Wed Apr 27, 2016 9:20 pm</p><hr />
]]></content>
	</entry>
	</feed>
