View unanswered posts | View active topics It is currently Sat Mar 25, 2017 5:04 am



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

Joined: Fri Feb 23, 2001 3:00 am
Posts: 3621
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:
Code:
isNumber $yn $number
if ($yn = TRUE)
  if ($value > 0) // now it's safe, we verified it
    echo "Mathematical!!"
  end
end


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.

+EP+


Thanks EP

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

_________________
Image
HHT 2015 Champs: Cloud09
Big Game 2016 Champs: Draft team


Classic Style Games Here:
telnet://Cruncherstw.no-ip.biz:2002

flash client: http://Cruncherstw.no-ip.biz:2004/PlayTW.html
Web page from 1990's: http://tradewars.fament.com/Cruncher/tradewar.htm
Blog with current server info: http://cruncherstw.blogspot.com
E-mail: Cruncherstw@gmail.com
http://www.facebook.com/CrunchersTW


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

Joined: Sat Feb 27, 2016 1:01 am
Posts: 139
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

Quote of the month: "It’s pretty easy to avoid but I’ve just been living life on the edge." — Hammer


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: No registered users and 2 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:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware.