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

	<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-02-09T14:49:18-04:00</updated>

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

		<entry>
		<author><name><![CDATA[user]]></name></author>
		<updated>2007-02-09T14:49:18-04:00</updated>

		<published>2007-02-09T14:49:18-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=70330#p70330</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=70330#p70330"/>
		<title type="html"><![CDATA[storing multiple variables (counters + names) in 1 file]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=70330#p70330"><![CDATA[
You should add <div class="codebox"><p>Code: </p><pre><code>bind evnt - prerehash saveCounters</code></pre></div> to make sure you don't load old data if you .rehash ...or you could prevent it from loading the file if the counter array exists...<div class="codebox"><p>Code: </p><pre><code>if {[file exists counterdata.tcl]&amp;&amp;![info exists counter]} {source counterdata.tcl }</code></pre></div><p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=2878">user</a> — Fri Feb 09, 2007 2:49 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[BCyo+8C4]]></name></author>
		<updated>2007-02-09T13:52:42-04:00</updated>

		<published>2007-02-09T13:52:42-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=70327#p70327</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=70327#p70327"/>
		<title type="html"><![CDATA[storing multiple variables (counters + names) in 1 file]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=70327#p70327"><![CDATA[
thank you very much, i made it work <img class="smilies" src="https://forum.eggheads.org/images/smilies/icon_smile.gif" width="15" height="15" alt=":-)" title="Smile"> wouldn't have been able to do so without your help<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=8166">BCyo+8C4</a> — Fri Feb 09, 2007 1:52 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[user]]></name></author>
		<updated>2007-02-09T08:43:08-04:00</updated>

		<published>2007-02-09T08:43:08-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=70315#p70315</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=70315#p70315"/>
		<title type="html"><![CDATA[storing multiple variables (counters + names) in 1 file]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=70315#p70315"><![CDATA[
<blockquote class="uncited"><div>I just don't get how/where to put the array data in normal strings and increase one of them. Would be nice if you could point out what I have to do.</div></blockquote>There is (like demond said) no need to read/parse the file every time you want to access the data. Just load it ONCE on startup and keep the data in a global variable. Then, on a regular interval OR when you make changes (if you need the file to match the actual data at all times) save it.<br><br>Eg:<div class="codebox"><p>Code: </p><pre><code># load the data if it existsif {[file exists counterdata.tcl]} {source counterdata.tcl}# saving it when ever the userfile/channel file is saved:bind evnt - save saveCountersproc saveCounters x {global countersavearray counter counterdata.tcl}# /msg bot !incall will increase ALL counters by 3bind msg - !incall incallcountersproc incallcounters {nick uhost hand text} {global counterforeach cnick [array names counter] {incr counter($cnick) 3}}# /msg bot !incme will increase YOUR counter by 1 and display the new valuebind msg - !incme incyourcounterproc incyourcounter {nick uhost hand text} {global counter# first, make sure there is a counter element for that nick...if {[info exists counter($nick)]} {incr counter($nick)} else {# if it doesn't exist, create it...set counter($nick) 1}puthelp "PRIVMSG $nick :Your new count is $counter($nick)"}</code></pre></div><p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=2878">user</a> — Fri Feb 09, 2007 8:43 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[BCyo+8C4]]></name></author>
		<updated>2007-02-09T07:25:17-04:00</updated>

		<published>2007-02-09T07:25:17-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=70313#p70313</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=70313#p70313"/>
		<title type="html"><![CDATA[storing multiple variables (counters + names) in 1 file]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=70313#p70313"><![CDATA[
i tried you tcl array solution, but i don't really get it<br><br>counterdata.tcl:<div class="codebox"><p>Code: </p><pre><code>array set counter {nick 123 anothernick 456}</code></pre></div>the normal tcl:<div class="codebox"><p>Code: </p><pre><code>bind msg n !triggerincreasecounterproc increasecounter {nick uhost hand text} {source counterdata.tclforeach counter nickn {        set counter($nickn)}savearray counter counterdata.tcl# debug lineputserv "PRIVMSG $nick :$counter(nick)"}proc savearray {array file {mode w}} {    upvar 1 $array var    set f [open $file $mode]    # the file will be empty if no array by that name exists.    if {[array exists var]} {       puts $f [list array set $array [array get var]]    }    close $f } </code></pre></div>I just don't get how/where to put the array data in normal strings and increase one of them. Would be nice if you could point out what I have to do.<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=8166">BCyo+8C4</a> — Fri Feb 09, 2007 7:25 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[user]]></name></author>
		<updated>2007-02-08T07:10:19-04:00</updated>

		<published>2007-02-08T07:10:19-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=70285#p70285</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=70285#p70285"/>
		<title type="html"><![CDATA[storing multiple variables (counters + names) in 1 file]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=70285#p70285"><![CDATA[
I think an array is well suited for the type of data you want to store...<div class="codebox"><p>Code: </p><pre><code># this proc will save an array as tcl code that will create the array when executedproc savearray {array file {mode w}} {upvar 1 $array varset f [open $file $mode]# the file will be empty if no array by that name exists.if {[array exists var]} {puts $f [list array set $array [array get var]]}close $f}# create some elementsset counter(nick) 123 set counter(anothernick) 456# save them:savearray counter counterdata.tcl# load them back in:source counterdata.tcl</code></pre></div>The concept is identical to the code demond provided, except the array is stored as tcl code instead of storing list elements as lines in the file.<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=2878">user</a> — Thu Feb 08, 2007 7:10 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[demond]]></name></author>
		<updated>2007-02-08T06:29:53-04:00</updated>

		<published>2007-02-08T06:29:53-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=70281#p70281</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=70281#p70281"/>
		<title type="html"><![CDATA[storing multiple variables (counters + names) in 1 file]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=70281#p70281"><![CDATA[
<blockquote class="uncited"><div>I used search but couldn't find anything. Could you please point me to a thread with instructions/examples?</div></blockquote><a href="http://forum.egghelp.org/viewtopic.php?t=11184" class="postlink">http://forum.egghelp.org/viewtopic.php?t=11184</a><p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=5056">demond</a> — Thu Feb 08, 2007 6:29 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[rosc2112]]></name></author>
		<updated>2007-02-08T06:11:18-04:00</updated>

		<published>2007-02-08T06:11:18-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=70277#p70277</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=70277#p70277"/>
		<title type="html"><![CDATA[storing multiple variables (counters + names) in 1 file]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=70277#p70277"><![CDATA[
Plenty of examples of reading/writing files, there's even a FAQ about it under "basic file operations"   <a href="http://forum.egghelp.org/viewtopic.php?t=6885" class="postlink">http://forum.egghelp.org/viewtopic.php?t=6885</a><br><br>..  Also look at the lindex command.<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=7395">rosc2112</a> — Thu Feb 08, 2007 6:11 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[BCyo+8C4]]></name></author>
		<updated>2007-02-08T05:55:37-04:00</updated>

		<published>2007-02-08T05:55:37-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=70276#p70276</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=70276#p70276"/>
		<title type="html"><![CDATA[storing multiple variables (counters + names) in 1 file]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=70276#p70276"><![CDATA[
I used search but couldn't find anything. Could you please point me to a thread with instructions/examples?<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=8166">BCyo+8C4</a> — Thu Feb 08, 2007 5:55 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[demond]]></name></author>
		<updated>2007-02-07T23:51:53-04:00</updated>

		<published>2007-02-07T23:51:53-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=70272#p70272</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=70272#p70272"/>
		<title type="html"><![CDATA[storing multiple variables (counters + names) in 1 file]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=70272#p70272"><![CDATA[
as it's been pointed out countless times already, you should read the entire file, once only, on script's startup, into a list; then manipulate that list as you wish, typically on events that your script handles; save the list periodically into a file<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=5056">demond</a> — Wed Feb 07, 2007 11:51 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[BCyo+8C4]]></name></author>
		<updated>2007-02-07T06:31:12-04:00</updated>

		<published>2007-02-07T06:31:12-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=70252#p70252</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=70252#p70252"/>
		<title type="html"><![CDATA[storing multiple variables (counters + names) in 1 file]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=70252#p70252"><![CDATA[
just had the idea of writing and deleting the lines like this, but i'd still need a way to read a) certain entries (to get the old value) and b) all values (to print stats like "nick: 123, anothernick: 456" to channel. if someone could please give me a hint on how to do that.. <img class="smilies" src="https://forum.eggheads.org/images/smilies/icon_smile.gif" width="15" height="15" alt=":)" title="Smile"><br><br><br>exec echo -e "$nick: $number" &gt;&gt; counter.txt<br><br>exec awk -f alfa.awk -v was=$nick counter.txt<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=8166">BCyo+8C4</a> — Wed Feb 07, 2007 6:31 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[BCyo+8C4]]></name></author>
		<updated>2007-02-07T06:01:26-04:00</updated>

		<published>2007-02-07T06:01:26-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=70251#p70251</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=70251#p70251"/>
		<title type="html"><![CDATA[storing multiple variables (counters + names) in 1 file]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=70251#p70251"><![CDATA[
Hi,<br>is it possible to store counters for multiple persons in one file?<br>I know how to do it for one file per person, but having just one file would be somewhat nicer. I imagine the file looking like this:<br><br>nick 123<br>anothernick 456<br>...<br><br>Would be nice if someone could help me<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=8166">BCyo+8C4</a> — Wed Feb 07, 2007 6:01 am</p><hr />
]]></content>
	</entry>
	</feed>
