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

	<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>2003-07-08T21:16:55-04:00</updated>

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

		<entry>
		<author><name><![CDATA[Darkj]]></name></author>
		<updated>2003-07-08T21:16:55-04:00</updated>

		<published>2003-07-08T21:16:55-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=23210#p23210</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=23210#p23210"/>
		<title type="html"><![CDATA[Writing to a file]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=23210#p23210"><![CDATA[
Yea I caught that<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=3459">Darkj</a> — Tue Jul 08, 2003 9:16 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[slennox]]></name></author>
		<updated>2003-07-08T02:00:19-04:00</updated>

		<published>2003-07-08T02:00:19-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=23189#p23189</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=23189#p23189"/>
		<title type="html"><![CDATA[Writing to a file]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=23189#p23189"><![CDATA[
I don't know if you already spotted the error yourself, but the first line should have been:<br><div class="codebox"><p>Code: </p><pre><code>if {[set n [lsearch -glob $list {$locatebot *}]] != -1} {</code></pre></div><p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=13034">slennox</a> — Tue Jul 08, 2003 2:00 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[Darkj]]></name></author>
		<updated>2003-07-07T22:05:26-04:00</updated>

		<published>2003-07-07T22:05:26-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=23188#p23188</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=23188#p23188"/>
		<title type="html"><![CDATA[Writing to a file]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=23188#p23188"><![CDATA[
Awesome, got it working now, thanks for the help.<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=3459">Darkj</a> — Mon Jul 07, 2003 10:05 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[slennox]]></name></author>
		<updated>2003-07-07T10:23:19-04:00</updated>

		<published>2003-07-07T10:23:19-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=23178#p23178</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=23178#p23178"/>
		<title type="html"><![CDATA[Writing to a file]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=23178#p23178"><![CDATA[
The in-between part might look something like<br><div class="codebox"><p>Code: </p><pre><code>if {[set n [lsearch -glob $list {$locatebot *}]]} {  lreplace $list $n $n [list $locatebot $location $action]} else {  lappend list [list $locatebot $location $action]}</code></pre></div>I also want to point out at the start of your proc that you should split the $arg before using lindex on it, e.g.<br><div class="codebox"><p>Code: </p><pre><code>  set locatebot [lindex [split $arg] 0]  set location [lindex [split $arg] 1]  set action [join [lrange [split $arg] 2 end]]</code></pre></div>otherwise it may have problems handing input containing special characters like brackets.<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=13034">slennox</a> — Mon Jul 07, 2003 10:23 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[Darkj]]></name></author>
		<updated>2003-07-07T09:00:09-04:00</updated>

		<published>2003-07-07T09:00:09-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=23177#p23177</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=23177#p23177"/>
		<title type="html"><![CDATA[Writing to a file]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=23177#p23177"><![CDATA[
I don't really have much experiencing with lists and working with lists.  I understand what you are saying, but I still get this part:<br><br>1) Retrieve all items from list (file)<br>2) Check list to see if item exists and if not add it<br>3) Create a new list (oldlist + newentry/modified entry)<br><br><br>I understand the saving and reading of the file, just not sure how to parse it to check for things....<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=3459">Darkj</a> — Mon Jul 07, 2003 9:00 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[slennox]]></name></author>
		<updated>2003-07-06T23:16:17-04:00</updated>

		<published>2003-07-06T23:16:17-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=23161#p23161</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=23161#p23161"/>
		<title type="html"><![CDATA[Writing to a file]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=23161#p23161"><![CDATA[
Do you have experience with using list commands (lindex, lreplace, etc.)? If so, it would probably be easier for you to read the file into a list variable (where each element represents a line of the file), edit the list, then overwrite the file with the new lines. I find this easier than working with the file directly (although it's probably less efficient).<br><div class="codebox"><p>Code: </p><pre><code>set file [open bots.db r]set lines [split [read -nonewline $file] \n]close $file</code></pre></div>Now you just do your modifications to $lines. When you're done:<br><div class="codebox"><p>Code: </p><pre><code>set file [open bots.db w]puts -nonewline $file [join $lines \n]close $file</code></pre></div>That will overwrite the old file.<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=13034">slennox</a> — Sun Jul 06, 2003 11:16 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[Darkj]]></name></author>
		<updated>2003-07-06T22:04:27-04:00</updated>

		<published>2003-07-06T22:04:27-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=23158#p23158</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=23158#p23158"/>
		<title type="html"><![CDATA[Writing to a file]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=23158#p23158"><![CDATA[
I've been working on this for hours and its gone through many revisions.<br>Basically what I am trying to do, is setup a command like this:<br><br>!location BotName BotsLocation(Ingame) What-the-bot-is-doing<br><br>Now this is all manual, so I'm just storing it to a file.<br><br>Now heres the code:<div class="codebox"><p>Code: </p><pre><code>proc locate { nick user hand chan arg } {  set locatebot [lindex $arg 0]  set location [lindex $arg 1]  set action [lrange $arg 2 end]  if {$locatebot == ""} {    puthelp "PRIVMSG $chan :The bot you specified does not match any bot in my database."    return 0  }  if {$location == ""} {    puthelp "PRIVMSG $chan :Not a valid location."    return 0  }  if {$action == ""} {    puthelp "PRIVMSG $chan :You have to specify what the bot is currently doing."    return 0  }  set file [open bots.db w+]  set found 0  set index ""  while {![eof $file]} {     gets $file line     if {[string match $locatebot [lindex $line 0]]} {         set found 1     }   }  if {$found == 1} {  puts $file "$locatebot $location $action"  putserv "PRIVMSG $chan :The location and action of $locatebot have been added to the database."  return  } else {  puts $file "$locatebot $location $action"  putserv "PRIVMSG $chan :The location and action of $locatebot have been changed in the database."  return  }} </code></pre></div>Basically i'm trying to check to see if there is an entry for the bot already, and if there is, I want it to replace it, otherwise I want it to add a new entry.  If someone can give me some insight as to what is wrong, it would be a big help.<br><br>Thanks<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=3459">Darkj</a> — Sun Jul 06, 2003 10:04 pm</p><hr />
]]></content>
	</entry>
	</feed>
