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

	<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>2011-04-29T10:00:35-04:00</updated>

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

		<entry>
		<author><name><![CDATA[nml375]]></name></author>
		<updated>2011-04-29T09:58:35-04:00</updated>

		<published>2011-04-29T09:58:35-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=96792#p96792</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=96792#p96792"/>
		<title type="html"><![CDATA[[SOLVED] Set Variable to Line in File / Write Variable]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=96792#p96792"><![CDATA[
Sorry, seems I forgot to increase the value of rpday at the end of the proc.. I'll update my previous post to correct the issue in a sec..<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=8052">nml375</a> — Fri Apr 29, 2011 9:58 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[Seka]]></name></author>
		<updated>2011-04-29T09:43:34-04:00</updated>

		<published>2011-04-29T09:43:34-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=96791#p96791</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=96791#p96791"/>
		<title type="html"><![CDATA[[SOLVED] Set Variable to Line in File / Write Variable]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=96791#p96791"><![CDATA[
<blockquote class="uncited"><div><div class="codebox"><p>Code: </p><pre><code>if {[catch {source rpday.tcl} err]} {  set ::rpday 1}set ::rpchan "#Bot_Test"bind time - "00 00 * * *" tchangeproc tchange {min hour day month year} {  global rpchan  switch -exact -- $::rpday {    1 {putquick "TOPIC $::rpchan :It is Day One!"}    2 {putquick "TOPIC $::rpchan :It is Day Two!"}    #... and so on...    #until the default case, which maches if none of the above does...    default {      putquick "TOPIC $::rpchan :It is Day Eleven!"      set ::rpday 0    }  }  set fd [open "rpday.tcl" "WRONLY CREAT TRUNC"]  puts $fd [list set ::rpday $::rpday]  close $fd}</code></pre></div></div></blockquote>It looks like the above script is stuck on the first entry in the "switch" statement. As it stands, at midnight, the topic is always changed to "It is Day One!" and never anything else in the list.<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=11646">Seka</a> — Fri Apr 29, 2011 9:43 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[Seka]]></name></author>
		<updated>2011-04-26T13:48:07-04:00</updated>

		<published>2011-04-26T13:48:07-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=96773#p96773</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=96773#p96773"/>
		<title type="html"><![CDATA[[SOLVED] Set Variable to Line in File / Write Variable]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=96773#p96773"><![CDATA[
Awesome.<br><br>Solved.<br><br>Thanks again!<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=11646">Seka</a> — Tue Apr 26, 2011 1:48 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[nml375]]></name></author>
		<updated>2011-04-26T13:35:36-04:00</updated>

		<published>2011-04-26T13:35:36-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=96770#p96770</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=96770#p96770"/>
		<title type="html"><![CDATA[[SOLVED] Set Variable to Line in File / Write Variable]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=96770#p96770"><![CDATA[
Escape them as \[ \]<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=8052">nml375</a> — Tue Apr 26, 2011 1:35 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[Seka]]></name></author>
		<updated>2011-04-26T13:18:47-04:00</updated>

		<published>2011-04-26T13:18:47-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=96768#p96768</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=96768#p96768"/>
		<title type="html"><![CDATA[[SOLVED] Set Variable to Line in File / Write Variable]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=96768#p96768"><![CDATA[
Looks like that is going to do it. I just need to format my topic a little better. I can't figure out how to keep the script from thinking that the brackets in the topic are code.<br><br>Thanks for your help, NML!<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=11646">Seka</a> — Tue Apr 26, 2011 1:18 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[nml375]]></name></author>
		<updated>2011-04-29T10:00:35-04:00</updated>

		<published>2011-04-24T12:28:09-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=96737#p96737</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=96737#p96737"/>
		<title type="html"><![CDATA[[SOLVED] Set Variable to Line in File / Write Variable]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=96737#p96737"><![CDATA[
Please indent your code properly when posting, it makes spotting issues such as the extra } in your code that much easier to spot... not to mention reading the code.<br><br>First, since you named your variable rpday, not state, you'll have to change that in the save-code as well..<br>Also, if you go with the script-solution, you don't need to write the value to "restore"; I'd suggest you only use one or the other to avoid confusion, not both..<br><br>Also a hint, since you're building such many states on a single expression (variable), I'd considder using switch instead of those stacked if/elseif/else's...<br><br>Finally, as for reading the generated rpday.tcl upon startup; I'd use a catch-statement - just so I wouldn't have to bother making sure the file is always created (yes, I'm lazy). I'll even add a default value in case there was an error loading the file...<br><div class="codebox"><p>Code: </p><pre><code>if {[catch {source rpday.tcl} err]} {  set ::rpday 1}set ::rpchan "#Bot_Test"bind time - "00 00 * * *" tchangeproc tchange {min hour day month year} {  global rpchan  switch -exact -- $::rpday {    1 {putquick "TOPIC $::rpchan :It is Day One!"}    2 {putquick "TOPIC $::rpchan :It is Day Two!"}    #... and so on...    #until the default case, which maches if none of the above does...    default {      putquick "TOPIC $::rpchan :It is Day Eleven!"      set ::rpday 0    }  }  incr ::rpday  set fd [open "rpday.tcl" "WRONLY CREAT TRUNC"]  puts $fd [list set ::rpday $::rpday]  close $fd}</code></pre></div>Edit: Corrected missing "incr ::rpday"<br>Edit: Corrected missing edit note...<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=8052">nml375</a> — Sun Apr 24, 2011 12:28 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[Seka]]></name></author>
		<updated>2011-04-24T11:46:42-04:00</updated>

		<published>2011-04-24T11:46:42-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=96736#p96736</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=96736#p96736"/>
		<title type="html"><![CDATA[[SOLVED] Set Variable to Line in File / Write Variable]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=96736#p96736"><![CDATA[
Ok. So, here's what I've got. It is untested, so far.<br><br>Let me know if I need to change anything, please:<br><div class="codebox"><p>Code: </p><pre><code>set channel "#Bot_Test"# Open the TCL with the variable?set fd [open "restore" "WRONLY CREAT TRUNC"]puts $fd $rpdayclose $fd # Execute every day at midnight?bind time - "00 00 * * *" tchange# Execute the proc.proc tchange {min hour day month year} {global channelif {$::rpday == 1} {putquick "TOPIC $channel :It is Day 1!"incr ::rpday} elseif {$::rpday == 2} {putquick "TOPIC $channel :It is Day 2!"incr ::rpday} elseif {$::rpday == 3} {putquick "TOPIC $channel :It is Day 3!"incr ::rpday} elseif {$::rpday == 4} {putquick "TOPIC $channel :It is Day 4!"incr ::rpday} elseif {$::rpday == 5} {putquick "TOPIC $channel :It is Day 5!"incr ::rpday} elseif {$::rpday == 6} {putquick "TOPIC $channel :It is Day 6!"incr ::rpday} elseif {$::rpday == 7} {putquick "TOPIC $channel :It is Day 7!"incr ::rpday} elseif {$::rpday == 8} {putquick "TOPIC $channel :It is Day 8!"incr ::rpday} elseif {$::rpday == 9} {putquick "TOPIC $channel :It is Day 9!"incr ::rpday} elseif {$::rpday == 10} {putquick "TOPIC $channel :It is Day 10!"incr ::rpday} elseif {$::rpday == 11} {putquick "TOPIC $channel :It is Day 11!"set ::rpday 1}  set fd [open "rpday.tcl" "WRONLY CREAT TRUNC"]  puts $fd [list set state $::rpday]  close $fd }}</code></pre></div>Also, do I need to create the "rpday.tcl" script in advance, or just enter the "source/rpday.tcl" entry in the bots conf?<br>what should the contents of that script look like, so that the variable can be read properly?<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=11646">Seka</a> — Sun Apr 24, 2011 11:46 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[nml375]]></name></author>
		<updated>2011-04-22T18:50:09-04:00</updated>

		<published>2011-04-22T18:50:09-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=96725#p96725</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=96725#p96725"/>
		<title type="html"><![CDATA[[SOLVED] Set Variable to Line in File / Write Variable]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=96725#p96725"><![CDATA[
The first problem with the code you posted, is that state is a local variable. The script-solution I mentioned "only" works with global variables (it could be made to work with local variables as well, but the hazzle really isn't worth it..  just use a global variable instead..)<br><br>Assuming we use a globalspace variable ::state instead; the posted code would only need one instance of the "save-code", provided that we add it at the end of the "example" proc, that we place the code at the end of the proc, and that we do not exit the proc prematurely (no return statements, etc).<br><div class="codebox"><p>Code: </p><pre><code>pub example {nick host handle channel text} {  if {$::state == 1} {    putserv "TOPIC $channel :It is day 1!"    incr ::state  } elseif {$::state == 2} {    putserv "TOPIC $channel :It is day 2!"    set ::state 1  }  set fd [open "restore.tcl" "WRONLY CREAT TRUNC"]  puts $fd [list set state $::state]  close $fd}</code></pre></div>Btw, I fixed the issues where you use variable substitutions unintentinally: set $state 1 =&gt;set state 1; incr $state =&gt; incr state<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=8052">nml375</a> — Fri Apr 22, 2011 6:50 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[Seka]]></name></author>
		<updated>2011-04-22T11:38:34-04:00</updated>

		<published>2011-04-22T11:38:34-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=96720#p96720</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=96720#p96720"/>
		<title type="html"><![CDATA[[SOLVED] Set Variable to Line in File / Write Variable]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=96720#p96720"><![CDATA[
Thank you both for the quick responses. I was able to rig something together, using the documentation.<br><br>nml375, <br><br>It looks like what you're suggesting could significantly lower the amount of code in my primary script.<br><br>My question is this, though. If I need to increment the value of the variable and store it in several different scenarios, would I need to repeat that code snippet throughout the script?<br><br>Example:<br><div class="codebox"><p>Code: </p><pre><code>pub example{nick host channel text} {if {$state == 1} {putserv "TOPIC $channel :It is day 1!"incr $state} elseif {$state == 2} {putserv "TOPIC $channel :It is day 2!"set $state 1}}</code></pre></div>Would your snippet be repeated after the "incr $state" in each expression?<br><br>Edit:<br><br>The proc is actually a time bind, but I just used the above code as an example.<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=11646">Seka</a> — Fri Apr 22, 2011 11:38 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[nml375]]></name></author>
		<updated>2011-04-22T11:01:36-04:00</updated>

		<published>2011-04-22T11:01:36-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=96719#p96719</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=96719#p96719"/>
		<title type="html"><![CDATA[[SOLVED] Set Variable to Line in File / Write Variable]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=96719#p96719"><![CDATA[
There are a few ways of doing this..<br>However, I'd probably settle with restoring the value when your eggdrop is restarted, rather than everytime the variable is read.<br><br>One of the simplest ways of doing this, is actually to have your code write a script that sets the value.. then all you need to do is add a "source restore.tcl" to your config-file<br><div class="codebox"><p>Code: </p><pre><code>...#assuming variable is named "state"set fd [open "restore.tcl" "WRONLY CREAT TRUNC"]puts $fd [list set state $state]close $fd...</code></pre></div>The above code writes a single line to the file restore.tcl, containing a (safe) set command to restore the value of "state". It should be fairly trivial to embed in your current code.<br><br>Other ways would be to just write the value to the file, and restore it by opening the file with read-access, reading the line, and restoring the value of the variable using the read value..<br><div class="codebox"><p>Code: </p><pre><code>...#assuming variable is named "state"set fd [open "restore" "WRONLY CREAT TRUNC"]puts $fd $stateclose $fd...if {[catch {open "restore" "RDONLY"} fd]} {  #unable to open file, does not exist?  putlog "Error restoring state: $fd"  return} else {  set ::state [gets $fd]  close $fd}...</code></pre></div><p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=8052">nml375</a> — Fri Apr 22, 2011 11:01 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[willyw]]></name></author>
		<updated>2011-04-22T10:52:00-04:00</updated>

		<published>2011-04-22T10:52:00-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=96718#p96718</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=96718#p96718"/>
		<title type="html"><![CDATA[[SOLVED] Set Variable to Line in File / Write Variable]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=96718#p96718"><![CDATA[
There is some very helpful info on file operations, here:<br><br><a href="http://forum.egghelp.org/viewtopic.php?t=6885" class="postlink">http://forum.egghelp.org/viewtopic.php?t=6885</a><br><br><br>Probably more than what you need.... it sounds like you need to write only one line, with one number on it, to the file.<br><br>You might also find some useful info here:<br><a href="http://www.tcl.tk/man/tcl8.5/TclCmd/open.htm#M7" class="postlink">http://www.tcl.tk/man/tcl8.5/TclCmd/open.htm#M7</a><br>or close to there.<br><a href="http://www.tcl.tk/man/tcl8.5/TclCmd/open.htm" class="postlink">http://www.tcl.tk/man/tcl8.5/TclCmd/open.htm</a><br><br><br>The main page is:<br><a href="http://www.tcl.tk/man/tcl8.5/TclCmd/contents.htm" class="postlink">http://www.tcl.tk/man/tcl8.5/TclCmd/contents.htm</a><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> — Fri Apr 22, 2011 10:52 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[Seka]]></name></author>
		<updated>2011-04-26T13:49:05-04:00</updated>

		<published>2011-04-22T09:36:06-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=96717#p96717</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=96717#p96717"/>
		<title type="html"><![CDATA[[SOLVED] Set Variable to Line in File / Write Variable]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=96717#p96717"><![CDATA[
I am pretty sure I know how to write a variable to a line in a file. My goal here is to use an outside file to "record" the state of a variable, so that if the bot resets it doesn't forget what the variable was set to the last time it accessed the script.<br><br>Let me explain.<br><br>I need to increment the value of a variable, in order for the bot to know what change to make on which day, in the course of eleven days. I just realized that by initializing the variable the way I do in the script, that if the bot dies or resets the CONF, it will start the variable from scratch.<br><br>So, every time I increment the variable, I want to write the value to a file. Then, pull that value from that file, each time the bot needs it for the script. Thus, avoiding repeating the same action two or more days in a row.<br><br>What I need:<br><br>I can't quite figure out the code to set a variable to a line in a file, then after the variable is increased an increment, overwrite that file line with the new value.<br><br>I'd really appreciated some help with this!<br><br>Thank you.<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=11646">Seka</a> — Fri Apr 22, 2011 9:36 am</p><hr />
]]></content>
	</entry>
	</feed>
