News | Tutorials | Games | Downloads | Links | Contact |
Featured Author: -blendenzo-
|
Tutorials - Blender Game Engine
Allowing the User to Input Textby blendenzo, with special thanks to Social and z3r0_dDue to bugs with the Firefox Blender plugin, it is recommended that you view this tutorial using Internet Explorer with the Blender 2.25 web plugin. Example files (zipped package): Not ready yet... Version Info: Blend made with 2.42a. Compatible with all versions of the BGE.
Basic Text Input
Allowing basic user input via the keyboard is relatively simple in the Blender Game Engine.
The Keyboard Sensor provides a simple interface for recording keystrokes and storing them
to a variable. Look at the image below:When the boolean property listed in "LogToggle" has a value of "True" the user's keystrokes are recorded to the "Target" property. In the example above, as long as prop is True, whatever the user types will be recorded to Text. Since Text is the display value of the bitmap text object, the user's input will be displayed directly to the screen. Social demonstrates this basic function in text_input.blend (126 kb). The plugin below shows the in-game results.
Firefox users: Due to an apparent bug with the Firefox plugin, you must navigate away from this page while the plugin is showing, then use your browser's back button to return here before the text will display properly. This applies to all plugins on this page. Password Input
Text input can easily be used for password entry. I modified Social's .blend to test
the value of Text against a pre-defined password. Download
password_input.blend (130 kb) and take a look. In this example I've used three bitmap text
objects. The first instructs the user to "Enter Password." The second text object receives
and displays the user's input. The third will display "Password Correct" if the user enters
the correct password. Take a look at the middle text object. In its logic you will find
that I've added a property with the password value.Now look at the Logic Bricks. When the user presses the carriage return key (Enter), the value of Text is tested to see if it is the same as password. If it is, the message "Password Correct" is displayed. Notice that the expression controller "TextIsPass" is connected between two text objects. The plugin below demonstrates this setup in-game. Use the [Left Ctrl] key to confirm your password, as the plugin does not recognize the [Enter] key.
Masked Passwords
Generally the user prefers for passwords to be masked while they are inputing them. This way
bystanders cannot see what is being typed. This can be achieved by sending the keyboard log to
a property other than Text, then using a short Python script to output the correct
number of mask characters to the Text property. Begin by adding an extra property to
the text input object. We'll call it input, since it will be receiving the keyboard
input.Now go to the Blender Text Editor and make a new file named "Mask.py". Here is the script (you can paste it into the Blender Text Editor using [Ctrl+Shift+V]):
-blendenzo Back to the tutorials index... |
|||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
Website design by Tony "blendenzo" DiRienzo. All content © Copyright Tony DiRienzo unless otherwise noted.