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 Discussion / limit characters for input

Author
Message
mediafanatic
10
Years of Service
User Offline
Joined: 24th Oct 2013
Location:
Posted: 26th Oct 2013 04:09
I want to limit the amount of letters the user can input using the input command. Is this possible?
Sergey K
20
Years of Service
User Offline
Joined: 4th Jan 2004
Location:
Posted: 27th Oct 2013 15:45
not sure how DB works, but i can give ya an example of DBP wich should be the same

1st, you need to be able to input a text while looping, for that, you can use the entry$() command..



you may find some bugs here as you try to extend the typing limit, but its all fixable. as long you got the idea, you will be fine.

Stream SnifferTools/Plugins/Models/Games and more!
LBFN
17
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 29th Oct 2013 05:37
Sergey K, with a couple of edits, your code does work. DBC does not recognize two forward slashes as the beginning of a REM statement.

mediafanatic, I have some code you could try also:



My screen flickers unless I do it something like this. Maybe it's my comp or Windows 7 or something, but this works fine for me. It clears the entry buffer every time, so you can check if the key pressed is what you want (i.e. you may want only numbers, only letters, etc).

So many games to code.....so little time.
Libervurto
17
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 4th Nov 2013 16:48 Edited at: 4th Nov 2013 16:49
I can think of two ways, the simpler but crude way:


You'll have to test this works because I can't atm:



Formerly OBese87.
BN2 Productions
20
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 4th Nov 2013 22:19
Quote: "backspace= 3&(backspace*2|keystate(14)) "


I'm interested. How does that work?

Great Quote:
"Time...LINE??? Time isn't made out of lines...it is made out of circles. That is why clocks are round!" -Caboose
Libervurto
17
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 5th Nov 2013 14:37 Edited at: 5th Nov 2013 14:37
BN2: (I'm about to hit you with a load of phrases that I coined and you wont see anywhere else.)

backspace= 3&(backspace*2|keystate(14))
This is an autonomous variable: a variable whose assignment is self-referencial. The simplest example of an autonomous variable is x= x, but a more useful example would be a common binary flip-flop, such as, isOddPass= 1 - isOddPass. Autonomous variables have a kind of entropy, their past values effecting their future values.

The form of backspace= 3&(backspace*2|keystate(14)), or more generally, variable= 3&(variable*2|trigger) -- which I dubbed "silkey" after Silverman, who wrote it, and the fact that its common use is for detecting input -- employs two bits: the first stores the binary state of the trigger, the second is the previous trigger state shifted along one bit. The bitwise AND operation simply cuts off any extra bits, limiting the variable to two bits in length.


Formerly OBese87.
BN2 Productions
20
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 6th Nov 2013 18:23
Interesting! Very clever! I had to do some reading up on bitwise operators, and if I'm understanding this right, that will return 4 possible values, 0-3 that correspond to the following cases:
0-still off
1-just turned on
2-just turned off
3-still on

I like it

Great Quote:
"Time...LINE??? Time isn't made out of lines...it is made out of circles. That is why clocks are round!" -Caboose
Libervurto
17
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 6th Nov 2013 19:03
Yes, that's right. If you right it in binary it is more intuitive:
00 - idle
01 - onPress
10 - onRelease
11 - hold

I will link you to the thread I made a while ago on this subject. http://forum.thegamecreators.com/?m=forum_view&t=207193&b=1&p=0


Formerly OBese87.

Login to post a reply

Server time is: 2024-04-27 03:21:58
Your offset time is: 2024-04-27 03:21:58