Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Code Snippets / [DBP] User Input Function

Author
Message
HeavyAmp
18
Years of Service
User Offline
Joined: 25th Oct 2006
Location: Castle in the Sky!
Posted: 11th Nov 2007 06:24 Edited at: 11th Nov 2007 19:20
Lets try this again, lol. User Input function



Better to be dead, than to live your life afraid.
dark coder
22
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 11th Nov 2007 07:20
It works, but:

Why use Entry$() when you aren't using the main features of it, i.e. storing multiple key inputs per call, backspace. For instance my current keyboard settings enable me to backspace around 10 chars/sec, entry$() will store the backspace chars so you should be able to parse these and remove them rather than making your own backspace routine.

Also it's possible for your method to miss user keys as you are first checking for user input via Scancode() then checking Entry$() for the entered char which seems rather pointless. You should have If Entry$() <> "" or i]If Len( Entry$() )[/i].

As said above you aren't checking for multiple chars per frame, so it's possible for someone to enter 2 or more characters per frame should their PC lag and your code will fail to read them all as you aren't looping through the length of Entry$().

Furthermore your function edits the hard coded UserInput string, which isn't the best method for user input. What if I have multiple input fields? Then It'd have to write extra code to swap out UserInput. Your best bet is to write a function where the user passes their string and you filter Entry$() and return the new string back.

Lastly, your example shows entering your name however unless you expect people from the Victorian era to play this they likely won't have numbers in there names. This is fine however in my input routines I often require underscores, commas and what not. It would be best if your function had parameters to specify which type of char you wanted to filter out.

HeavyAmp
18
Years of Service
User Offline
Joined: 25th Oct 2006
Location: Castle in the Sky!
Posted: 11th Nov 2007 19:15
My main reason for only taking one letter at a time was that I didn't want all the functionality of the keyboard. If you use Entry$() as it is it also records tabs, enter and a whole lot of other symbols that I didnt want in there. The problem with just using $entry and filtering as it is by the time you make your variable= Entry$() again you have to filter the whole string again. You could always take out what you didn't want after the user presses enter but the user probably won't know whats been taken out and whats not.

Quote: "You should have If Entry$() <> "" or i]If Len( Entry$() )."


Thats a better way of doing it ill update it after this post.

Quote: "Furthermore your function edits the hard coded UserInput string"


Its only designed to get user Input not handle multiple input fields. You would still use the function to do this though eg.
If Cursor=Field1 then Field1data=UserInput. Its not that hard to use it for multiple input fields.

Quote: "Lastly, your example shows entering your name however unless you expect people from the Victorian era to play this they likely won't have numbers in there names. This is fine however in my input routines I often require underscores, commas and what not. It would be best if your function had parameters to specify which type of char you wanted to filter out."


Thats true that sometimes you need underscores, fullstops etc. I only really wrote what I needed from the function but down the track I can see me needing input other than letters and numbers. It wont be too hard to allow it to accept the symbols that I need just allow the ASC() to accept whatever number the String of the symbol is. I think its a good idea having another parameter setting what type of data you want from the user although it might make the function a bit longer.

I have to agree with you that the backspace in the input function is rubbish. Ive been trying to think of another way to go about it. Any ideas are welcome.

Better to be dead, than to live your life afraid.

Login to post a reply

Server time is: 2024-11-22 13:12:08
Your offset time is: 2024-11-22 13:12:08