View unanswered posts | View active topics It is currently Thu Oct 19, 2017 10:25 pm



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

Joined: Fri Feb 23, 2001 3:00 am
Posts: 3658
Location: USA
Unread post 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.

_________________
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


Sat Oct 17, 2015 11:17 pm
Profile ICQ WWW
Commander

Joined: Sun Feb 25, 2001 3:00 am
Posts: 1707
Location: Guam USA
Unread post 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://202.151.82.243:2002
Team Speak3 Servers for TradeWars @
Zoom's Team Speak Server
ts3server://vs26.tserverhq.com:7214 This is where I'm at.

Founding Member -=[Team Kraaken]=- Ka Pla
Image

Image
Image


Sun Oct 18, 2015 3:12 am
Profile ICQ WWW
Ambassador
User avatar

Joined: Fri Feb 23, 2001 3:00 am
Posts: 3658
Location: USA
Unread post 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.

_________________
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


Sun Oct 18, 2015 7:50 am
Profile ICQ WWW
Chief Warrant Officer

Joined: Sat Jul 14, 2012 6:32 pm
Posts: 104
Unread post 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
Profile
Ambassador
User avatar

Joined: Fri Feb 23, 2001 3:00 am
Posts: 3658
Location: USA
Unread post 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 :)

_________________
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


Sun Oct 18, 2015 12:49 pm
Profile ICQ WWW
Commander

Joined: Sun Feb 25, 2001 3:00 am
Posts: 1707
Location: Guam USA
Unread post 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://202.151.82.243:2002
Team Speak3 Servers for TradeWars @
Zoom's Team Speak Server
ts3server://vs26.tserverhq.com:7214 This is where I'm at.

Founding Member -=[Team Kraaken]=- Ka Pla
Image

Image
Image


Sun Oct 18, 2015 1:18 pm
Profile ICQ WWW
Ambassador
User avatar

Joined: Fri Feb 23, 2001 3:00 am
Posts: 3658
Location: USA
Unread post 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 macro

I think I'll just parse the planet number, that makes more sense since you need to be in the citadel to start.

_________________
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


Sun Oct 18, 2015 9:09 pm
Profile ICQ WWW
Ensign

Joined: Wed Nov 06, 2002 3:00 am
Posts: 259
Unread post 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 macro

I 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. :lol: 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
Profile
Commander

Joined: Sun Feb 25, 2001 3:00 am
Posts: 1707
Location: Guam USA
Unread post 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://202.151.82.243:2002
Team Speak3 Servers for TradeWars @
Zoom's Team Speak Server
ts3server://vs26.tserverhq.com:7214 This is where I'm at.

Founding Member -=[Team Kraaken]=- Ka Pla
Image

Image
Image


Tue Oct 20, 2015 12:46 pm
Profile ICQ WWW
Ensign

Joined: Wed Nov 06, 2002 3:00 am
Posts: 259
Unread post 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
Profile
Ambassador
User avatar

Joined: Fri Feb 23, 2001 3:00 am
Posts: 3658
Location: USA
Unread post 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")

_________________
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


Wed Oct 21, 2015 10:13 pm
Profile ICQ WWW
Commander

Joined: Sun Feb 25, 2001 3:00 am
Posts: 1707
Location: Guam USA
Unread post 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://202.151.82.243:2002
Team Speak3 Servers for TradeWars @
Zoom's Team Speak Server
ts3server://vs26.tserverhq.com:7214 This is where I'm at.

Founding Member -=[Team Kraaken]=- Ka Pla
Image

Image
Image


Thu Oct 22, 2015 5:21 am
Profile ICQ WWW
Ambassador
User avatar

Joined: Fri Feb 23, 2001 3:00 am
Posts: 3658
Location: USA
Unread post 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 29

I'm using Win7

_________________
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


Thu Oct 22, 2015 8:54 pm
Profile ICQ WWW
Gameop
User avatar

Joined: Tue Nov 19, 2002 3:00 am
Posts: 1047
Location: USA
Unread post 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 29

I'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
Profile ICQ
Commander
User avatar

Joined: Tue Oct 07, 2003 2:00 am
Posts: 1102
Location: Augusta, GA
Unread post 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
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 17 posts ]  Go to page 1, 2  Next

Who is online

Users browsing this forum: No registered users and 5 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.