Re: Using get_key() to input a string

new topic     » goto parent     » topic index » view thread      » older message » newer message

Pete wrote:

> Kevin Sieger wrote:
> >
> > Yes, there is an easier way to input a string, but the use of the
> > get_key allows me to implement real time in a multi-user rpg I'm
> > developing.  The problem I have is this: discluding the use of ports.e
> > for getting remote strings, in order to get a local string (so someone
> > can play locally) the game loop constantly checks the kb buffer for
> > characters, loads them into a sequence and grabs the entire string on a
> > carriage return.  I then send the string to a parser to break the string
> > down into verbs, nouns etc.
> > Anyway, with get_key, you have to manually echo the character back to
> > the screen, but there is not good way to implement the backspace key
> > (8).  Yes, it works fine for actually deleting the character sent
> > (through some commands) but what about erasing the character on screen?
>
> Here's a possible solution:
>
> include graphics.e
>
> sequence buffer, pos
> buffer = ""
> integer char
> char = 0
> while char != 27 do  -- quit if esc is pressed
>   char = get_key()
>
>   if char=8 and length(buffer)>0 then
>     buffer=buffer[1..length(buffer)-1]
>     pos = get_position()
>     if pos[2] > 1 then  -- move cursor one column left
>       pos[2] = pos[2] - 1
>     elsif pos[1] > 1 then  -- wrap cursor
>       pos[2] = 80 -- assuming 80 char wide display
>       pos[1] = pos[1] - 1
>     end if
>     position(pos[1], pos[2])
>     puts(1, " ")
>     position(pos[1], pos[2])
>   elsif char>=32 and char<=122 then
>     buffer=buffer&char
>     puts(1, {char})
>   elsif char = 13 then
>     printf(1, "\nbuffer = \"%s\"\n", {buffer})
>     buffer = ""
>   end if
>
> end while
>
> > All of the input characters work fine, but trying to use backspace
> > displays the ascii representation of 8, which is a rectangle with a
> > diamond (or circle?) cut out of the middle.  In C (ack!) I could use %c
> > and 8 and it would work fine (I'm assuming, used C code as example).
> >
> > Any clues?
>
> I think Euphoria doesn't use the same low level commands to print
> characters as C would.  Writing to video memory is much faster than
> using the video interrupt, but you don't get the character conversions.
>
> > Thanks!
> > Kevin
>
> Anytime :)
>
> Later,
> --
>                   _____         _____        _____
>    ________      /\    \       /\    \      /\    \
>   /   \    \    /  \____\     /  \____\    /  \____\
>  /  _  \____\  /   / ___/_   /   /____/   /   / ___/_
> /  / \  |____|/   / /\____\ /    \    \  /   / /\____\
> \  \_/ /    / \   \/ / ___/_\     \    \ \   \/ / ___/_
>  \    /____/   \    / /\    \\/\   \    \ \    / /\    \
>   \   \    \    \   \/  \____\  \   \    \ \   \/  \____\
>    \   \    \    \      /    /   \   \____\ \      /    /
>     \   \____\    \    /    /     \  /    /  \    /    /
>      \  /    /     \  /    /       \/____/    \  /    /
>       \/____/       \/____/xseal at harborside.com\/____/

  Yeah, I figured I'd have to do it that way...sigh...this would mean locking
the cursor as soon as a key is detected from the user, as anything could
happen in a real time loop (the game doesn't wait for input, it creates
encounters, changes weather, etc).  But I could implement this in many ways,
like a seperate window just for user input, or loading all strings to be sent
to users screen into sequences that will print when after the user starts
input only when they delete down to an empty string, or when they hit return.
My, the %c would have been much easier <G>.

Thanks again,
Kevin
(with no fancy logo }tongue )

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu