ID:1888321
 
Redundant
Applies to:
Status: Redundant

This feature has already been implemented, or is already achievable with existing methods.
Title says it all here, I would like to be able to set a range to inputs requiring a number to be submitted. If in range of those numbers, it should return the number. Else-wise, it should return false.

If currently possible, I apologize. I tested to be sure and got a 'unused label' warning on the second number(post- 'to'). Also, I don't seem to be able to find and real references to 'to' in the reference(although, I didn't search very hard).
I suspect the suggested behavior would be odd for BYOND.

It should return false (FALSE== 0), if the number is not in the range?
What then in the case of n = input("") as num in -1 to 1 ?

It'd need to return a non-numeric value, probably null (which is not equal to 0/FALSE) but then, you'd also have to do an explicit comparison to null rather than something like, !n.

Or a runtime, which you'd then cleanup with try/catch, or something. Or...you could just use a while loop for all of this:

mob/verb/test()
var/number = input_num_range(-1, 1)
world << number

proc/input_num_range(min, max)
do
. = input("") as num
. = (. in min to max) ? . : null
while(. == null)

//I just realized, moments after this post, this could be simpler:

proc/input_num_range(min, max)
do
. = input("") as num
while(!(. in min to max))


In response to Super Saiyan X
I thought of that while trying to decide on a example of how it should return. I am aware FALSE compiles as 0, which is what held me up on making the post. I couldn't decide on anything better and couldn't see a usage where you would want it to return anything other than 0. null was my second choice, but given that most(assumingly) would assume the response a number and not check after a input, it would return a error. My third choice was to prevent the player from submitting the input with improper answers, but I'm not sure if that's even feasible in DS as it is.
In response to NNAAAAHH
NNAAAAHH wrote:
I thought of that while trying to decide on a example of how it should return. I am aware FALSE compiles as 0, which is what held me up on making the post. I couldn't decide on anything better and couldn't see a usage where you would want it to return anything other than 0. null was my second choice, but given that most(assumingly) would assume the response a number and not check after a input, it would return a error. My third choice was to prevent the player from submitting the input with improper answers, but I'm not sure if that's even feasible in DS as it is.

Look at what I just edited in my post - fairly easy solution, that's pretty much how soft-coded inputs with specific value needs are handled right now (really, the only way I could think of)

Tbh, I would probably go with the soft coded route rather see this as a BYOND feature - it's much handier (and you could give it any behavior you want), could work with more than just a range.
In response to Super Saiyan X
That is actually a fairly interesting take on the feature I hadn't thought of yet. Still, the request was for the feature to be native. Great example, though.
Kaiochao resolved issue (Redundant)