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.

negative number not allowed in script

Support & discussion of released scripts, and announcements of new releases.
Post Reply
p
parakeet
Voice
Posts: 3
Joined: Sun Jun 04, 2023 5:22 am

negative number not allowed in script

Post by parakeet »

The script: Conversion v1.00, date 20-05-2001 by DrN
Filename: tempc100.tcl
Download URL: https://tclarchive.org/search.php?str=conversion

There are 3 binds:
!c2f
!f2c
!convert

It's a pretty nice script and I like it a lot but I had to fix all the formulas for the conversions as they gave incorrect results.

For conversions between Celsius and Fahrenheit with !c2f or !f2c, if I enter a negative number the script tells me that my input is incorrect. I know that the procedure 'isnum' checks for a number but it doesn't seem to account for negative numbers. This is not a big deal since I can use: !convert -20 celsius * farenheit instead which does work because it doesn't use the proc isnum, but it's a bit annoying nonetheless.

Is there a way to modify the isnum procedure to allow for negative numbers without adding or modifying too much code?
User avatar
caesar
Mint Rubber
Posts: 3776
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

Here's two options: scan and string is integer.

Code: Select all

bind pub - [cmdchar]c2f pub_c2f
proc pub_c2f {nick uhost hand chan rest} {
set data [lindex $rest 0]
if {![isnum $data]} {putserv "PRIVMSG $nick :Calling syntax is ${cmdchar_}c2f <tempeture in celsius>"
                    return 1}
set cdata [expr $data * 1.8 + 32]
putserv "PRIVMSG $chan :$data degrees celsius is $cdata degrees farenheit."
}
becomes:

Code: Select all

bind pub - [cmdchar]c2f pub_c2f

proc pub_c2f {nick uhost hand chan text} {
	if {[scan $text {%d} no] != 1} {
		puthelp "PRIVMSG $nick :Calling syntax is ${cmdchar_}c2f <temperature in celsius>"
		return
	}
	set temp [expr $no * 1.8 + 32]
	puthelp "PRIVMSG $chan :$no degrees Celsius is $temp degrees Farenheit."
}
or:

Code: Select all

bind pub - [cmdchar]c2f pub_c2f

proc pub_c2f {nick uhost hand chan text} {
	set no [lindex [split $text] 0]
	if {![string is integer $no]} {
		puthelp "PRIVMSG $nick :Calling syntax is [cmdchar]c2f <tempeture in celsius>"
		return
	}
	set temp [expr $no * 1.8 + 32]
	puthelp "PRIVMSG $chan :$no degrees Celsius is $temp degrees Farenheit."
}
Adapt the rest of the code in a similar manner.

Edit: typo fix.
Last edited by caesar on Mon Jun 05, 2023 3:14 am, edited 1 time in total.
Once the game is over, the king and the pawn go back in the same box.
User avatar
CrazyCat
Revered One
Posts: 1252
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Post by CrazyCat »

Small ad : you can try https://gitlab.com/tcl-scripts/tcl-util ... ersion.tcl (need to get https://gitlab.com/tcl-scripts/tcl-util ... units.json) which is a try to do an expansible conversion tool

(Official download: https://scripts.eggdrop.fr/details-Conversion-s258.html)
p
parakeet
Voice
Posts: 3
Joined: Sun Jun 04, 2023 5:22 am

Post by parakeet »

Thank you caesar and CrazyCat. So far caesar's code don't seem to work very well.
User avatar
caesar
Mint Rubber
Posts: 3776
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

Fixed typos above as I did a copy/paste and forgot to replace some variables.
Once the game is over, the king and the pawn go back in the same box.
p
parakeet
Voice
Posts: 3
Joined: Sun Jun 04, 2023 5:22 am

Post by parakeet »

Thank you caesar, I will test this tomorrow. :D
Post Reply