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.

Problem with isnumber

Old posts that have not been replied to for several years.
Locked
T
TheElite

Problem with isnumber

Post by TheElite »

Well... I was trying to use isnumber but it doesn't seem to work. I made it echo to the channel to see what it returned and it always returns 0, no matter what.

Code: Select all

  putmsg $chan "$dice $sides blah[isnumber dice]blah[isnumber sides]blah"
I put the blahs there to see if I was getting spaces in it. Howerver, there were no spaces. Here's the variable assignment.

Code: Select all

  set dice [string range $text 0 [string wordend $text 0]]
  set sides [string range $text [string wordend $text 0] [string wordend $text 1]]
If anyone can help, it'd be much appreciated.
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

isnumber is not a Tcl command, unless it is provided by a tool set or another script.

Besides that, the way you use the variables in the script is wrong.

using "isnumber dice" is like asking if the word "dice" is a number. This is clearly faulse, so it returns 0.

Maybe you are trying to use the variable named "dice". In that case, you should use "isnumber $dice".
T
TheElite

Post by TheElite »

It's not a TCL command but it's a function provided by alltools.tcl

I tried doing it with a $... it still didn't work.
T
TheElite

Post by TheElite »

Ok, well I figured out that it was putting in whitespace... is there any function that gets rid of whitespace?
User avatar
stdragon
Owner
Posts: 959
Joined: Sun Sep 23, 2001 8:00 pm
Contact:

Post by stdragon »

You use isnumber like this:

if {[isnumber $blah]} {
putlog "it's a number"
}

Might I ask why (or where) you need to get rid of whitespace? If you're getting whitespace in your numbers, then you're extracting them wrong. But anyway, you get rid of whitespace like this (well, it's one way):

regsub -all " " $blah "" blah

I think I should point out that [string range] is not the best way to extract words from a string. Also, if you know you're trying to extract 2 numbers, you can use 1 regexp statement to extract and validate both of them.
T
TheElite

Post by TheElite »

Thanks... I found that in another post after I had posted that... sorry :(
Locked