Program a pass-code with logic bricks?

I made a computer, and I want to add a puzzle with a pass-code. I would prefer to do this with logic-bricks, but it the python code is simple that would be okay.

It is possible in logic bricks, but it’s annoying and somewhat hard. I’d suggest python.

It shouldn’t be too hard either. You simply have to convert the players keystorkes into text (which you can do with an all keys sensor with a log property), then search through the log and see if you’ve found a password.

How do I conduct the searching part?

check this out,

I don’t know how to convert keys to unicode so,
I checked against a string I built from the .events

the password is pass

check ‘readout’ for generating these,

Attachments

passwordPrompt.blend (404 KB)

Python… >.<… Maybe one day this will make sense, xD.

the keypress = sens.event

it spits out [115,1] for S , a different one for each letter,

there is probably a easy way to convert it, but I don’t know it, as this is the first time I attempted to log input,

so what I did, is logged keypresses, and then printed it, then copied what I printed, then used that to check against

Take one of the many easy online courses, even if it is only a couple sections. It helped me get a grasp on python and how to use lists etc. (codeacademy)

Why does “convert unicode to character” produce no good results? what is the right question?

Whilst it does appear that the Blender events use Unicode characters, the bge.events module provides you with bge.events.EventToCharater(code, is_shifted) as a function for converting to string.

I made a logic brick template, here. 4 Scenes. The ‘Main game’ scene is the game, so start there. change the password in the 'PassCode" scene. Python is only used for mouselook and movement. there is no length restriction on the password as well, which would need the python ‘len()’ function. The password is ‘password’; case sensitive.
FirstPersonUseCode.blend (649 KB)

Thanks goose, that is what I was looking for,

Is there a way to get the character based on the currently set keyboard layout, not the US one?

Wouldn’t it be enough to use the keyboard sensors’s log function and simply check the logging property?

The only “complication” is that the property sensor can’t compare properties. The expression controller is good enough for this.


Unfortunately, no (which is a shame).

I could not even find a Python library that does keyboard mapping.

Monster, I wanted a readout that starts blank, and fills up as you hit keys,

so I don’t think a log would work,

next up is my first uv alphabet sheet. (never even used one yet)

Just clean the target property to perform an “enter reset” (not included in the above image).

I think Monster is right about using key log.
It even records special characters such as question mark so your password can be anything.

If you would like a script you can use in your project, here’s a basic one.

password.blend (402 KB)
(password is “I am a robot!”, capital “I”)

@BPR
When i downloaded your file I noticed that you didn’t turn on the line number or syntax highlighting functions in the text window. I don’t know if it’s just something that happened when I downloaded the file, or if you don’t usually use them.

For everyone who doesn’t, I highly recommend using those features, if not an external editor for python. It helps to make the code much more readable while you’re typing, making coding much easier.

Uh, the goal is to have a computer with a locked drive. I can program the computer with ease, but the locked part that prompts the user with UI that has text input is where I struggle. Not the prompting part, just the pass-word input part.

I do not see the difference between a prompt (place for text input) and password input.

When you have a prompt you should also have whatever the user entered. You can verify that against a stored password.

There is a simple way to do this with logic bricks: You create a plane with a text texture, you put it’s text property to string and assign a keyboard to a sign (ex: Numpad1 = property “Text” add 1) (if you have only a numpad to create it just take five mins to do) and, for exemple if you don’t want the number to be infinite, you set a property sensor “interval” with no minimum and 999 for maximum if you want to limit the numbers to three. And then you set a property with the solution number associated with another trigger. I know it’s a little bit long to set up, but it’s the best way Iknow with logic bricks only, and you can duplicate this system to create easily multiple puzzle systems in your game :wink:

How could I display the text on screen? Like I don’t know of a way to do so, according to a grid. I mean, add object would stack the text.