Code: Select all
...
#assuming variable is named "state"
set fd [open "restore.tcl" "WRONLY CREAT TRUNC"]
puts $fd [list set state $state]
close $fd
...
Code: Select all
...
#assuming variable is named "state"
set fd [open "restore" "WRONLY CREAT TRUNC"]
puts $fd $state
close $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: Select all
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: Select all
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: Select all
set channel "#Bot_Test"
# Open the TCL with the variable?
set fd [open "restore" "WRONLY CREAT TRUNC"]
puts $fd $rpday
close $fd
# Execute every day at midnight?
bind time - "00 00 * * *" tchange
# Execute the proc.
proc tchange {min hour day month year} {
global channel
if {$::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: Select all
if {[catch {source rpday.tcl} err]} {
set ::rpday 1
}
set ::rpchan "#Bot_Test"
bind time - "00 00 * * *" tchange
proc 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
}
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.Code: Select all
if {[catch {source rpday.tcl} err]} { set ::rpday 1 } set ::rpchan "#Bot_Test" bind time - "00 00 * * *" tchange proc 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 }