Author |
Message |
Cruncher
Ambassador
Joined: Fri Feb 23, 2001 3:00 am Posts: 4011 Location: USA
|
 Restricting User Input
I have some fields that must have an alpha string value from the user.
I'm not seeing an operand "/=NULL" in TWX Proxy Script Reference.
I've tried if ( $var = 0 ) and if ( $var = "0" ) but that didn't work with a string.
_________________
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
|
Sat Oct 17, 2015 11:17 pm |
|
 |
Vid Kid
Commander
Joined: Sun Feb 25, 2001 3:00 am Posts: 1833 Location: Guam USA
|
 Re: Restricting User Input
Cruncher wrote: I have some fields that must have an alpha string value from the user.
I'm not seeing an operand "/=NULL" in TWX Proxy Script Reference.
I've tried if ( $var = 0 ) and if ( $var = "0" ) but that didn't work with a string. Try IF ($var = "") Vid
_________________ TWGS V2 Vids World on Guam Port 2002 Telnet://vkworld.ddns.net:2002 Discord @ DiverDave#8374 Vid's World Discord
Founding Member -=[Team Kraaken]=- Ka Pla
 Winners of Gridwars 2010 MBN Fall Tournament 2011 winners Team Kraaken Undisputed Champions of 2019 HHT Just for showing up!
The Oldist , Longist Running , Orginal Registered Owner of a TWGS server : Vids World On Guam
|
Sun Oct 18, 2015 3:12 am |
|
 |
Cruncher
Ambassador
Joined: Fri Feb 23, 2001 3:00 am Posts: 4011 Location: USA
|
 Re: Restricting User Input
Vid Kid wrote: Cruncher wrote: I have some fields that must have an alpha string value from the user.
I'm not seeing an operand "/=NULL" in TWX Proxy Script Reference.
I've tried if ( $var = 0 ) and if ( $var = "0" ) but that didn't work with a string. Try IF ($var = "") Vid That was the first thing I tried: Code: :LoopThis getInput $var "* Question for Player" getText $var $value "" "" echo "**"& ANSI_14 " This is how you answered " & ANSI_10 $value "**" if ($value = " ") echo ANSI_15 " You must answer" goto :LoopThis end
This code is still accepting an empty string.
_________________
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
|
Sun Oct 18, 2015 7:50 am |
|
 |
CBYNot
Chief Warrant Officer
Joined: Sat Jul 14, 2012 6:32 pm Posts: 104
|
 Re: Restricting User Input
Cruncher wrote: Vid Kid wrote: Cruncher wrote: I have some fields that must have an alpha string value from the user.
I'm not seeing an operand "/=NULL" in TWX Proxy Script Reference.
I've tried if ( $var = 0 ) and if ( $var = "0" ) but that didn't work with a string. Try IF ($var = "") Vid That was the first thing I tried: Code: :LoopThis getInput $var "* Question for Player" getText $var $value "" "" echo "**"& ANSI_14 " This is how you answered " & ANSI_10 $value "**" if ($value = " ") echo ANSI_15 " You must answer" goto :LoopThis end
This code is still accepting an empty string. Looks like you've got a space in if ($value = " ") - try as: if ($value = "") Also if the input you are attempting to get is a number you can restrict entries using the $isnum command to verify that the input is a number before moving on, and an elseif to verify that # is not 0.
_________________ "TW: A proud tradition of...change is the only constant."
-Val
|
Sun Oct 18, 2015 12:42 pm |
|
 |
Cruncher
Ambassador
Joined: Fri Feb 23, 2001 3:00 am Posts: 4011 Location: USA
|
 Re: Restricting User Input
CBYNot wrote: Cruncher wrote: That was the first thing I tried: Code: :LoopThis getInput $var "* Question for Player" getText $var $value "" "" echo "**"& ANSI_14 " This is how you answered " & ANSI_10 $value "**" if ($value = " ") echo ANSI_15 " You must answer" goto :LoopThis end
This code is still accepting an empty string. Looks like you've got a space in if ($value = " ") - try as: if ($value = "") Also if the input you are attempting to get is a number you can restrict entries using the $isnum command to verify that the input is a number before moving on, and an elseif to verify that # is not 0. Excellent, that did it for the strings. Silly little nuances of TWX that don't line up with what I've learned for C#. I am using isNumber, and that's fine, except that it also accepts the number 0, which I don't want. I suppose I could change that up and parse the planet number we're starting on, since I do a prompt check for Citadel. Thanks again... back to work 
_________________
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
|
Sun Oct 18, 2015 12:49 pm |
|
 |
Vid Kid
Commander
Joined: Sun Feb 25, 2001 3:00 am Posts: 1833 Location: Guam USA
|
 Re: Restricting User Input
For numbers try :
:Top GetInput $Value "* Number Question for Player" IsNumber $YN $Value IF ($YN = TRUE) and ($Value > "0") Else Got :Top End
Vid
_________________ TWGS V2 Vids World on Guam Port 2002 Telnet://vkworld.ddns.net:2002 Discord @ DiverDave#8374 Vid's World Discord
Founding Member -=[Team Kraaken]=- Ka Pla
 Winners of Gridwars 2010 MBN Fall Tournament 2011 winners Team Kraaken Undisputed Champions of 2019 HHT Just for showing up!
The Oldist , Longist Running , Orginal Registered Owner of a TWGS server : Vids World On Guam
|
Sun Oct 18, 2015 1:18 pm |
|
 |
Cruncher
Ambassador
Joined: Fri Feb 23, 2001 3:00 am Posts: 4011 Location: USA
|
 Re: Restricting User Input
Vid Kid wrote: For numbers try :
:Top GetInput $Value "* Number Question for Player" IsNumber $YN $Value IF ($YN = TRUE) and ($Value > "0") Else Got :Top End
Vid Thanks Vid Edit: Script compilation error: Unnecessary parameters after IF macroI think I'll just parse the planet number, that makes more sense since you need to be in the citadel to start.
_________________
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
|
Sun Oct 18, 2015 9:09 pm |
|
 |
SteveH_66
Ensign
Joined: Wed Nov 06, 2002 3:00 am Posts: 259
|
 Re: Restricting User Input
Cruncher wrote: Vid Kid wrote: For numbers try :
:Top GetInput $Value "* Number Question for Player" IsNumber $YN $Value IF ($YN = TRUE) and ($Value > "0") Else Got :Top End
Vid Thanks Vid Edit: Script compilation error: Unnecessary parameters after IF macroI think I'll just parse the planet number, that makes more sense since you need to be in the citadel to start. I can't speak to the rest of what you all are talking about here, I would have to study the code further, and math isn't my forte.  But if you ran Vid's code as it is in the quotes above, I think you might be getting that "Edit: Script compilation error: Unnecessary parameters after IF macro" error because of a typo. Vid or someone else should be able to confirm if I'm right, but I think "Got :Top" should read "Goto :Top" Hope that helps, if I'm correct and this is a typo. Edit : Also, while not having studied the code example Vid did for you, it seems like to me that there should be some kind of action to be taken that was left out of the code example between IF and Else. I think not having anything between IF and Else might throw an error code as well. Like : Quote: :Top GetInput $Value "* Number Question for Player" IsNumber $YN $Value IF ($YN = TRUE) and ($Value > "0") goto :startNextAction Else Goto :Top End My apologies Vid if this is not the case. Chalk it up to an amateur trying to debug your code lol
|
Tue Oct 20, 2015 2:26 am |
|
 |
Vid Kid
Commander
Joined: Sun Feb 25, 2001 3:00 am Posts: 1833 Location: Guam USA
|
 Re: Restricting User Input
Actually the typo was the Goto :Top
and you do not need anything between the IF else .. It will fall through ..
I am going to check the Getinput .. I see an * and do not like that .. so will check if that is ok ..
Yup , its ok to put in there .. so the only problem was the typo in the command goto.
Thanks for the catch. 2 heads are better then one.
Vid
_________________ TWGS V2 Vids World on Guam Port 2002 Telnet://vkworld.ddns.net:2002 Discord @ DiverDave#8374 Vid's World Discord
Founding Member -=[Team Kraaken]=- Ka Pla
 Winners of Gridwars 2010 MBN Fall Tournament 2011 winners Team Kraaken Undisputed Champions of 2019 HHT Just for showing up!
The Oldist , Longist Running , Orginal Registered Owner of a TWGS server : Vids World On Guam
|
Tue Oct 20, 2015 12:46 pm |
|
 |
SteveH_66
Ensign
Joined: Wed Nov 06, 2002 3:00 am Posts: 259
|
 Re: Restricting User Input
I just get lucky once in a while Vid, if you ever saw me scripting you would laugh your head off. Pulling my hair out for half an hour before I find the typo or where I messed the math up lol.
I didn't know you could have an IF without an 'action' or 'statement' (don't know what programmers would call it) after it. Thanks for pointing that out, it makes it easier for someone to write a script with a check in it.
I am guessing that is the purpose of the script block Cruncher is working on.
|
Tue Oct 20, 2015 2:03 pm |
|
 |
Cruncher
Ambassador
Joined: Fri Feb 23, 2001 3:00 am Posts: 4011 Location: USA
|
 Re: Restricting User Input
Vid Kid wrote: Actually the typo was the Goto :Top
and you do not need anything between the IF else .. It will fall through ..
I am going to check the Getinput .. I see an * and do not like that .. so will check if that is ok ..
Yup , its ok to put in there .. so the only problem was the typo in the command goto.
Thanks for the catch. 2 heads are better then one.
Vid Yeah, it wasn't the goto loop it was the if statement: IF ($YN = TRUE) and ($Value > "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
|
Wed Oct 21, 2015 10:13 pm |
|
 |
Vid Kid
Commander
Joined: Sun Feb 25, 2001 3:00 am Posts: 1833 Location: Guam USA
|
 Re: Restricting User Input
Cruncher wrote: Vid Kid wrote: Actually the typo was the Goto :Top
and you do not need anything between the IF else .. It will fall through ..
I am going to check the Getinput .. I see an * and do not like that .. so will check if that is ok ..
Yup , its ok to put in there .. so the only problem was the typo in the command goto.
Thanks for the catch. 2 heads are better then one.
Vid Yeah, it wasn't the goto loop it was the if statement: IF ($YN = TRUE) and ($Value > "0") That part is entirely correct , and works on Win 10. If you wrote it like : IF ($YN) and ($Value > "0") Which works for XP and Win 7 and 8 but will not work with Win 10 Win 10 sees the ($YN) as a null string and fails. I have tested scripts with Micro .. and almost every time I had to change the ($YN) to ($YN = TRUE) for them to work for his Win 10 box. Vid
_________________ TWGS V2 Vids World on Guam Port 2002 Telnet://vkworld.ddns.net:2002 Discord @ DiverDave#8374 Vid's World Discord
Founding Member -=[Team Kraaken]=- Ka Pla
 Winners of Gridwars 2010 MBN Fall Tournament 2011 winners Team Kraaken Undisputed Champions of 2019 HHT Just for showing up!
The Oldist , Longist Running , Orginal Registered Owner of a TWGS server : Vids World On Guam
|
Thu Oct 22, 2015 5:21 am |
|
 |
Cruncher
Ambassador
Joined: Fri Feb 23, 2001 3:00 am Posts: 4011 Location: USA
|
 Re: Restricting User Input
Cruncher wrote: Yeah, it wasn't the goto loop it was the if statement: IF ($YN = TRUE) and ($Value > "0")
Code: isNumber $test $value Line 29> if ($test = TRUE) and ($value >"0") echo ANSI_15 " oops, not a whole number. Please enter " goto :Loopthis end
Script compilation error: Unnecessary parameters after IF macro, line 29I'm using Win7
_________________
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
|
Thu Oct 22, 2015 8:54 pm |
|
 |
Kaus
Gameop
Joined: Tue Nov 19, 2002 3:00 am Posts: 1050 Location: USA
|
 Re: Restricting User Input
Cruncher wrote: Cruncher wrote: Yeah, it wasn't the goto loop it was the if statement: IF ($YN = TRUE) and ($Value > "0")
Code: isNumber $test $value Line 29> if ($test = TRUE) and ($value >"0") echo ANSI_15 " oops, not a whole number. Please enter " goto :Loopthis end
Script compilation error: Unnecessary parameters after IF macro, line 29I'm using Win7 space after >
_________________ Dark Dominion TWGS Telnet://twgs.darkworlds.org:23 ICQ#31380757, -=English 101 pwns me=- "This one claims to have been playing since 1993 and didn't know upgrading a port would raise his alignment."
|
Thu Oct 22, 2015 10:05 pm |
|
 |
ElderProphet
Commander
Joined: Tue Oct 07, 2003 2:00 am Posts: 1124 Location: Augusta, GA
|
 Re: Restricting User Input
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+
_________________ Claim to Fame: only guy to ever crack the TW haggle algorithm, and fig/shield/hold price formula, twice.
|
Thu Oct 22, 2015 10:06 pm |
|
 |
|