This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

figuring out a loop

Old posts that have not been replied to for several years.
W
Weirdo
Master
Posts: 265
Joined: Sat Apr 27, 2002 8:00 pm
Location: Manchester, England

Post by Weirdo »

Code: Select all

bind time - * time:pubnotice 
proc time:pubnotice {min hour day moth year} { 
	global chanl network notice active
	if {![string index $min 0]} { set min [string index $min 1] }
	if {[expr $min ^ 15]} { return }
	if {$active == 1} {
		puthelp "Notice %chanl(main) :$notice(public)"
		putlog "Notice sent to $chanl(main)" 
	}
}
Like this slim?[/code]
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

I have just noticed somthing rather strange, or rather, more anoying, and it requires work-arounds.

The time bind, has the current min, hour, day month and year passed as arguments to any trigger proc. Each argument is 2 digits long (year I aint sure about, I aint looked), no matter what it's value is overall.

When representing numbers in other languages like C, the number 02 is octal/hex (memory aludes me without my books), and 2 is decimal. As such, at 2 mins past the hour, odd things can happen.

When trying to reproduce this, on the only tclsh shell I could access, I found it impossible.
% set min 02
02
% expr $min % 5
2
% set min 00
00
% expr $min % 5
0
This leads me to suspect, that Tcl is interpreting the number being passed in the bind, as a actual number, and not a string. From what I can see, in the tests above, simply using

Code: Select all

if {$min % 5} { return }
Would do the trick, and as further unshown tests prooved, it did so. However, eggdrop (Tcl) still creates error out of this, during certain parts of the hour.

Wihtout being able to spend some time looking into the source, running some actual eggdrop tests and so on, the workarounds posted above, will have to be used, however, I have one final sugestion, should anyone want to test it. Try using

Code: Select all

set min [expr $min]
Instead of the "string" based commands. This may force Tcl to think different, but no gurentees.

The way things currently work, are part correct, but also seem part wrong too. I hope to find some longer term solution to the overall issue, of having to convert the mins value, so that basic math can be performed on it.
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

Just quickly, yes, that code should work. Though you might as well prod the [expr]

Code: Select all

if {$min % 15} { return }
and not
if {[expr $min % 15]} {
I also seem to have located why these are required.

This is a quote from the tcl man pages
* / %
Multiply, divide, remainder. None of these operands may be applied to string operands, and remainder may be applied only to integers. The remainder will always have the same sign as the divisor and an absolute value smaller than the divisor.
This would imply, that the min value, is infact a string, and not an integer, and would explain why my head was saying no while typing the previous post.

If working in Tcl script (the type we create for eggdrop, or command line processing), it seems that all variables are stored in some form of mixed form, where they are neither string or integers.

When working in C however (as eggdrop does), passing the string accross, stores it as a physical string, wihtout the ability to be loose in it's actions.

When I get my ass home tomorow, I am gonna write a letter of complaint to the government, for not allowing string there freedom :P

however, I do want it to be free like the rest of Tcl code, as it hampers normal calulations as noted by the errors.
W
Weirdo
Master
Posts: 265
Joined: Sat Apr 27, 2002 8:00 pm
Location: Manchester, England

Post by Weirdo »

FREEDOM FOR STRINGS :)

[16:00:00] <Natsuki-Chan> [16:00] Notice sent to #weirdo

with the code

if {![string index $min 0]} { set min [string index $min 1] }
if {$min % 15} { return }

Cause of a typo, it didnt do anything in channel. Should do next time :)

So this should happen every 15 mins? Or is it every hour?
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

OK - lets inspect the 2 lines of code in use.

The first, looks to see what the first character in the $min variable is. If it's a 0 (In most languages, 0 is seen as false), it will set the value of $min, to the second digit in the variable, leaving it only 1 character in length.

This means, that $min will no longer have it's 2 digit length, that has me so hot an bothered, and causing all these issues with errors.

The second line, does some simple math, to figure out what time throughout the hour it is.

If the time is 30 mins past the hour, the following happens.

Devide 20 by 15, and you get 1, with 5 remaining (remember, we are working with decimal whole numbers, and not floating points, so we don't get the 1.33333 crap).

If it is 30 min past, we get 2 and 0 remaining.

As you should see, the possible values that can be used as a remainder are
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14
So when there is 0 remaining, it must either be 0, 15, 30 or 45 mins past the hour.

Again, remember that the if command works by true and false values, with 0 being flase, and any other being true.

As such, if the remainder is 1 or upwards, that the code "return" is run, thus stopping the script, if it is 0, then it is skipped, causing the script to complete it's journey.
W
Weirdo
Master
Posts: 265
Joined: Sat Apr 27, 2002 8:00 pm
Location: Manchester, England

Post by Weirdo »

Ok, that is something i wold never thought of myself. Thank you very much slim. It works wonderfully, at 16:15 it did the notice in channel. thanks very much

In an hour and 45 mins, we do the switchover :)
Locked