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.

DarkBASIC Professional Discussion / How to limit user input with the INPUT command?

Author
Message
The Slayer
Forum Vice President
16
Years of Service
User Offline
Joined: 9th Nov 2009
Playing: (Hide and) Seek and Destroy on my guitar!
Posted: 24th Jul 2010 21:43
For my BRIXOID game I use the 'input' command to read the Name$ of the player and save it to file and that works as it should, but I need to limit the number of letters one can write. How would I do that? Any suggestions?

Thanks in advance!

Cheers

Slayer rules!!! Yeaaah, man!
HowDo
23
Years of Service
User Offline
Joined: 28th Nov 2002
Location: United Kingdom
Posted: 24th Jul 2010 22:33
This should do it.



Dark Physics makes any hot drink go cold.
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 24th Jul 2010 23:30
Quote: "How to limit user input with the INPUT command?"

You can't.
You can limit the string after it's returned by the INPUT command, but you can't stop the user entering anything they like.

You need to make yourself familiar with the ENTRY$() function, and maybe with my plug-in additions to that too.

Here's an example I've posted before, with the addition of a maximum input size:


The Slayer
Forum Vice President
16
Years of Service
User Offline
Joined: 9th Nov 2009
Playing: (Hide and) Seek and Destroy on my guitar!
Posted: 25th Jul 2010 00:37
Great example IanM! But, how would I implement your code into mine? And how to make the input stop after the returnkey has been pressed?

Here's the code that I used to read and write the Highscores (it's a code snippet I found on the forum):



Thanks

Cheers

Slayer rules!!! Yeaaah, man!
The Slayer
Forum Vice President
16
Years of Service
User Offline
Joined: 9th Nov 2009
Playing: (Hide and) Seek and Destroy on my guitar!
Posted: 27th Jul 2010 19:27
Well, while implementing IanM's code snippet into my game, I found some problems of which one is presumably a bug.
First the bug: I use the Bitmap Font plugin by ACCODE which I found on the forum to display the highscores and make them look neater than just plain text, and it works pretty good. But, after adding IanM's code which I use to add the new highscore, some strange issue appear. After I enter my name (with IanM's code) and go back to show the highscores, I get the error 'image does not exist at line...', but I'm sure the image is there and loaded, cuz' I added the 'if image exist() = 0' to make sure it would load. So, why does this happen? Is this some bug in the Bitmap Font plugin, or IanM's matrix commands? Or is there something else? Is it true that functions should be placed at the bottom of the code and the gosub routines just above them, or is it the other way around?

There's also another issue that I have with IanM's code. It runs fine on it's own, but when I added it in my game and you enter text, and then delete the text, the cursor jumps one position before the initial starting position.

So, I'm back to square one. Or, I use the Bitmap Font plugin and make the text neater but then the user can input as much letters as he/she wants (which I don't want), or I skip the Bitmap Font and use IanM's code to limit the numbre of letters inputted.

So, is there anyone who can help me sort this out?

Thanks in advance!

Cheers

Slayer rules!!! Yeaaah, man!
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 27th Jul 2010 23:24
It works for me without problem, however, you can try adding the following line after grabbing a copy of the entry buffer to see if it fixes the backspace problem for you:


Make sure that you are using the latest version of DBPro, in case there's a bug fix for that in earlier versions (although that would have to be a fairly early version).

Next, there are no image commands in my code at all. Therefore the missing image problem must be caused either by bitmap font plug-in or your own code.

Quote: "Is it true that functions should be placed at the bottom of the code and the gosub routines just above them, or is it the other way around? "

Doesn't matter.

The Slayer
Forum Vice President
16
Years of Service
User Offline
Joined: 9th Nov 2009
Playing: (Hide and) Seek and Destroy on my guitar!
Posted: 28th Jul 2010 00:19 Edited at: 28th Jul 2010 00:20
Quote: "It works for me without problem, however, you can try adding the following line after grabbing a copy of the entry buffer to see if it fixes the backspace problem for you:"

Well, it runs fine for me too on it's own, but not when I add it to my game.
But I will try that out later. I found a way around it, though. It's not as elegant as yours, but it works.

Quote: "Doesn't matter."

Just as I thought.

Thanks for answering, IanM!

Slayer rules!!! Yeaaah, man!

Login to post a reply

Server time is: 2026-07-25 07:01:55
Your offset time is: 2026-07-25 07:01:55