View unanswered posts | View active topics It is currently Mon Mar 25, 2019 1:19 am

Reply to topic  [ 17 posts ]  Go to page Previous  1, 2
 Restricting User Input 
Author Message
User avatar

Joined: Fri Feb 23, 2001 3:00 am
Posts: 3829
Location: USA
Unread post Re: Restricting User Input
ElderProphet wrote:
I can shed some light on this.

First thing, I think you need something to follow the IF test, before the ELSE... try throwing a comment in there.

Secondly, in many programming languages, logic tests are short-circuited... which is to say, if the first argument needs to be true, but isn't, then nothing else is tested. And you can extrapolate that short-circuit behavior on and on... if an argument fails its test, nothing further is tested... in many programming languages.

So, Vid's statement would be fine... except TWX scripts DO NOT short-circuit logic tests. So let's recap:
> isNumber $yn $number
> if ($yn =TRUE) AND ($value > 0)
So indeed, the first argument fails if it's not a number... but the second comparison will still be attempted, and throw an exception if $value isn't a number. Make sense? I tried to alter this behavior, but it was non-trivial, and I don't think I succeeded.

So, you have to nest any comparisons that require a number inside of the isNumber test:
isNumber $yn $number
if ($yn = TRUE)
  if ($value > 0) // now it's safe, we verified it
    echo "Mathematical!!"

Cruncher, why wouldn't you want the number zero to pass the isNumber test? You may be creating the zero just by testing a value. Share more, and I'll elaborate if it applies.


Thanks EP

The number I'm testing is a ship number, cannot equal "0".

HHT 2015 Champs: Cloud09
Big Game 2016 Champs: Draft team
2018 HHT Champs: Rock Stars

Classic Style Games Here:

Web page from 1990's: ... adewar.htm
Blog with current server info:

Fri Oct 23, 2015 5:51 pm
Profile ICQ WWW
Chief Warrant Officer
User avatar

Joined: Sat Feb 27, 2016 1:01 am
Posts: 149
Location: Molon Labe
Unread post Re: Restricting User Input
Yea, just to note on this subject, it seems the script will crash if you attempt to compare a string to a number, so numbers have to be confirmed first (using isNumber) and then their ranges tested in a nested if--AND/OR--end. That is to be safe anyways.

The object of life is not to be on the side of the majority, but to escape finding one’s self in the ranks of the insane.” — Marcus Aurelius

Sat Oct 01, 2016 7:38 am
Profile ICQ
Display posts from previous:  Sort by  
Reply to topic   [ 17 posts ]  Go to page Previous  1, 2

Who is online

Users browsing this forum: Majestic-12 [Bot] and 8 guests

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware.