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

	<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-13T20:09:02-04:00</updated>

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

		<entry>
		<author><name><![CDATA[stdragon]]></name></author>
		<updated>2002-11-13T20:09:02-04:00</updated>

		<published>2002-11-13T20:09:02-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=13146#p13146</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=13146#p13146"/>
		<title type="html"><![CDATA[Catching Decimal numbers in an if statement]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=13146#p13146"><![CDATA[
First thing, it's usually easier to understand if you break up the line into separate parts.<br><div class="codebox"><p>Code: </p><pre><code># Separate string into wordsset words [split $text]# Get first word (bantime)set bantime [lindex $words 0]# Split it by '.' in case there is oneset parts [split $bantime "."]# Get the first part and ignore the restset real_bantime [lindex $parts 0]</code></pre></div>The comments are a bit excessive (I wouldn't put them there for myself), but it's a lot easier to read than when everything is crammed on one line.<br><br>Just a note though, regexp would be a better function to use, I think.<br><br>regexp {(\d+)\S*\s*(.*)} $text ignore bantime reason<br><br>Read out loud, it means "at least one digit", "some non-space chars or none (e.g. the .2 part)", "some space chars (or none)", and then "any chars (the reason)".<br><br>Regexp syntax is weird at first, but then it's very logical and easy to use to parse just about anything in one line.<br><br>% set text "2;2    you're banned"      <br>2;2    you're banned<br>% regexp {(\d+)\S*\s*(.*)} $text ignore bantime reason<br>1<br>% puts $bantime  <br>2<br>% puts $reason<br>you're banned<br>%<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=8">stdragon</a> — Wed Nov 13, 2002 8:09 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[Weirdo]]></name></author>
		<updated>2002-11-13T19:50:58-04:00</updated>

		<published>2002-11-13T19:50:58-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=13144#p13144</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=13144#p13144"/>
		<title type="html"><![CDATA[Catching Decimal numbers in an if statement]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=13144#p13144"><![CDATA[
i really dont understand these lindex things at all. Spitting it simply i can just about get, that just confuses me still<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=1195">Weirdo</a> — Wed Nov 13, 2002 7:50 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[Papillon]]></name></author>
		<updated>2002-11-13T19:13:45-04:00</updated>

		<published>2002-11-13T19:13:45-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=13143#p13143</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=13143#p13143"/>
		<title type="html"><![CDATA[Catching Decimal numbers in an if statement]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=13143#p13143"><![CDATA[
<div class="codebox"><p>Code: </p><pre><code>set bantime2 [lindex [split [lindex [split $text] 0] .] 1]</code></pre></div>this is wrong.... if you trigger it with <em class="text-italics">!w3rk 2 2</em> it will first split <em class="text-italics">2 2</em>, then it will pick out the first element in the list.... "2", then it will try to split "2" at every . (none in this example), and now we come to where the wrong part is <img class="smilies" src="https://forum.eggheads.org/images/smilies/icon_wink.gif" width="15" height="15" alt=";)" title="Wink"> ... it will last take elemet number 2 from a list wich only consist of 1 element... that's why $bantime2 always will be empty.. if u replace the "1" in the script with a "0" I think you'll get what u want... like this:<div class="codebox"><p>Code: </p><pre><code>set bantime2 [lindex [split [lindex [split $text] 0] .] 0]</code></pre></div><p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=852">Papillon</a> — Wed Nov 13, 2002 7:13 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[Weirdo]]></name></author>
		<updated>2002-11-13T14:25:47-04:00</updated>

		<published>2002-11-13T14:25:47-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=13133#p13133</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=13133#p13133"/>
		<title type="html"><![CDATA[Catching Decimal numbers in an if statement]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=13133#p13133"><![CDATA[
<div class="codebox"><p>Code: </p><pre><code>set bantime2 [lindex [split [lindex [split $text] 0] .] 1]if {$bantime2 == ""} {set bantime2 $w3rkdefbantime}</code></pre></div>Currently the use of !w3rk 2 2 test doesnt return anything but the $w3rkdefbantime variable. For some reason it isnt picking up the "2" which is the bantime that i want to be used. <br><br>It didnt use to do this <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=1195">Weirdo</a> — Wed Nov 13, 2002 2:25 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[Anonymous]]></name></author>
		<updated>2002-10-26T13:23:50-04:00</updated>

		<published>2002-10-26T13:23:50-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=12414#p12414</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=12414#p12414"/>
		<title type="html"><![CDATA[Catching Decimal numbers in an if statement]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=12414#p12414"><![CDATA[
i don't know why people will do a ban 1.1 (or other characters). <br>The ban command is<br><br>!afk time reason with time in minutes, means an integer ! <br><br>The best way i think it's to allow only integers and u can test this with  if [isnumber $time]<br><br>other solution, perhaps ?<br><div class="codebox"><p>Code: </p><pre><code>set test "123,4" set what "" for {set loop 0} {$loop &lt; [strlen $test] } {incr loop} {     if { [regexp \[^0-9\] [string index $test $loop]]} {          break     } else {          set what "$what[string index $test $loop]"     }} return $whatreturns 123 in my example</code></pre></div><p>Statistics: Posted by Guest — Sat Oct 26, 2002 1:23 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[Weirdo]]></name></author>
		<updated>2002-10-26T12:41:30-04:00</updated>

		<published>2002-10-26T12:41:30-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=12408#p12408</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=12408#p12408"/>
		<title type="html"><![CDATA[Catching Decimal numbers in an if statement]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=12408#p12408"><![CDATA[
they try to break it <img class="smilies" src="https://forum.eggheads.org/images/smilies/icon_smile.gif" width="15" height="15" alt=":)" title="Smile"><br><br>if they use other characters in between the digits, does the "." become a "*" ?<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=1195">Weirdo</a> — Sat Oct 26, 2002 12:41 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[Anonymous]]></name></author>
		<updated>2002-10-26T12:37:55-04:00</updated>

		<published>2002-10-26T12:37:55-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=12407#p12407</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=12407#p12407"/>
		<title type="html"><![CDATA[Catching Decimal numbers in an if statement]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=12407#p12407"><![CDATA[
yep but why people will do a 1.1<br>why not a 1,1 or a 1;1 or ...<p>Statistics: Posted by Guest — Sat Oct 26, 2002 12:37 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[Weirdo]]></name></author>
		<updated>2002-10-26T12:37:19-04:00</updated>

		<published>2002-10-26T12:37:19-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=12406#p12406</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=12406#p12406"/>
		<title type="html"><![CDATA[Catching Decimal numbers in an if statement]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=12406#p12406"><![CDATA[
oooh, nice bit of code that, kind of confusing. So its a string inside a string. interesting indeed <img class="smilies" src="https://forum.eggheads.org/images/smilies/icon_smile.gif" width="15" height="15" alt=":)" title="Smile"><br><br>Thanks as always, it works perfectly <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=1195">Weirdo</a> — Sat Oct 26, 2002 12:37 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[ppslim]]></name></author>
		<updated>2002-10-26T12:19:41-04:00</updated>

		<published>2002-10-26T12:19:41-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=12402#p12402</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=12402#p12402"/>
		<title type="html"><![CDATA[Catching Decimal numbers in an if statement]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=12402#p12402"><![CDATA[
The "[lindex [split $text] 0]" will get the 1.1 out of the text. But to get only the whole number, wihtout the decimal, use<br><div class="codebox"><p>Code: </p><pre><code>set bantime [lindex [split [lindex [split $text] 0] .] 0]</code></pre></div><p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=2">ppslim</a> — Sat Oct 26, 2002 12:19 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[Anonymous]]></name></author>
		<updated>2002-10-26T12:06:28-04:00</updated>

		<published>2002-10-26T12:06:28-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=12401#p12401</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=12401#p12401"/>
		<title type="html"><![CDATA[Catching Decimal numbers in an if statement]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=12401#p12401"><![CDATA[
don't understand exactly<br><br>but why not using [isnumber $string], a proc on alltools.tcl<p>Statistics: Posted by Guest — Sat Oct 26, 2002 12:06 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[Weirdo]]></name></author>
		<updated>2002-10-26T08:42:24-04:00</updated>

		<published>2002-10-26T08:42:24-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=12394#p12394</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=12394#p12394"/>
		<title type="html"><![CDATA[Catching Decimal numbers in an if statement]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=12394#p12394"><![CDATA[
Ok, still havent found anything that i could use for this really. Is there a way i could split the ".*" from the number entered, so it would round it down?<br><div class="codebox"><p>Code: </p><pre><code>set bantime [lindex [split $text] 0 ]</code></pre></div>This is where the code fits into the script<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=1195">Weirdo</a> — Sat Oct 26, 2002 8:42 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[Weirdo]]></name></author>
		<updated>2002-10-25T08:01:20-04:00</updated>

		<published>2002-10-25T08:01:20-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=12358#p12358</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=12358#p12358"/>
		<title type="html"><![CDATA[Catching Decimal numbers in an if statement]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=12358#p12358"><![CDATA[
Hey again <img class="smilies" src="https://forum.eggheads.org/images/smilies/icon_smile.gif" width="15" height="15" alt=":)" title="Smile"><br><br>right, i am adding some validation to my !afk scripts. Basically. when you do <br><br>!afk 1 test<br><br>It bans you for one minute, with the reason test<br><br>(There is a reason i have this on my bot, a channel full of IRC addicts and procrastinators <img class="smilies" src="https://forum.eggheads.org/images/smilies/icon_razz.gif" width="15" height="15" alt=":P" title="Razz"> )<br><br>But, when you do<br><br>!afk 1.1 test<br><br>It bans you instantly, and for permanent. What i want to know, is how can i use an if statement to catch out these errors in the bantime? Namely the decimal points. what i ultimately want to do is to include this in the existing validation i have for this script, Which checks the number range, if that is wrong, then the script will not execute. I want to do the exact same thing with the Decimal Checker. <br><br>Any help?<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=1195">Weirdo</a> — Fri Oct 25, 2002 8:01 am</p><hr />
]]></content>
	</entry>
	</feed>
