View unanswered posts | View active topics It is currently Sun Oct 06, 2024 5:41 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: 4016
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".

_________________

BOTE 1998 Champs: Team Fament
HHT 2015 Champs: Cloud09
Big Game 2016 Champs: Draft team
HHT 2018 Champs: Rock Stars
Big Game 2019 Champs: Draft Team


Classic Style Games Here:
telnet://crunchers-twgs.com:2002

Web page from 1990's: https://web.archive.org/web/20170103155645/http://tradewars.fament.com/Cruncher/tradewar.htm
Blog with current server info: http://cruncherstw.blogspot.com
Discord: https://discord.gg/4dja5Z8
E-mail: Cruncherstw@gmail.com
FaceBook: 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: 193
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

TWX Proxy Reference Online


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 3 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.