1. Copy of: Re: Number Input
>Repost of Reply:
>>Bryan wrote: > . . .how do I let the player enter numbers (such
>>as a bet), >and have the variable equal the number entered and
>>not the ASCII number? > . . .<skipped> . . . They enter "15",
>>but the sequence >variable is set to {49,53} . . .
>> Bryan, I think the value() function would get the result
>>you need. You will have to include get.e to use it, but it
>>should return the number 15 from the string "15", etc. You
>>may want to check the library.doc file on this function, as I
>>believe it actually returns a sequence with the
>>first(second?)element being a status indicator.
>>Craig =
>Bryan,
>Maybe you can use the input function, written by 'unknown coder'
>(actually a corporate attempt of some coders). This function can
>also be found on the ftp site of Irv Mullins (that's his name, I think)
Sorry for mailing this when it was not yet finished. It should also conta=
in
the code:
--<start here>--
-- simple numerical input routine
include get.e
include graphics.e
function input(sequence prompt)
-- print a message and read in a number
-- returns a number, integer or float (atom)
sequence input, curpos
-- initialize input with values that are *not* valid
input =3D {1, 0}
puts(1, prompt) -- display message
while input[1] !=3D GET_SUCCESS do
-- repeat until valid number
curpos =3D get_position() -- read current cursor position
input =3D get(0) -- read from keyboard
position(curpos[1], curpos[2]) -- back if no valid input
end while
puts(1, '\n') -- start on a new line, not totally necessary
return input[2] -- second element of input should be valid number=
end function -- input
--<code ends here>--
--Using the function get(0) in this routine you don't need value(), since=
it is 'built in'.
-- examples:
integer bet
atom float
bet =3D input("Your bet please: ")
printf(1, "\nYour bet was %d\n", bet)
float =3D input("How much money do you have? ") -- input can be 12.52, =
f.i.
printf(1, "Double your money to %5.2f", float * 2)
Hope this helps,
Sincerely,
Ad Rienks
writing at 21:50 , =
on dinsdag 29 juli 1997
Using EMail Assist for WinCIM