Best way to realize a password field

  • #1, by marvelMonday, 01. May 2017, 19:11 3 years ago
    Hey guys,
    I need a passwort-field with a maximum of 10 chars.

    Example:

    The user has to type this password. Now I think about the best way to realize it. What would YOU suggest? I know of this demo: http://www.visionaire-studio.net/forum/thread/key-input-tech... But this is way too complex for my purpose and I don't need any quiz here wink

    Can anybody explain, what this script does exactly:

    local result = "" -- create an empty string
    local val

    function add(c)
     val = getObject("Game.GameCurrentScene.SceneValues[str_txt]")
     result = val:getStr(VValueString) .. c
     updateStr()
    end

    function remove()
     val = getObject("Game.GameCurrentScene.SceneValues[str_txt]")
     if string.len( val:getStr(VValueString) ) >; 0 then result = string.sub( val:getStr(VValueString), 1, -2); updateStr() end
    end

    function updateStr()
     val = getObject("Game.GameCurrentScene.SceneValues[str_txt]")
     val:setValue(VValueString, result)
    end

    function clear()
     stopAction("ActiveActions[display_text]")
     getObject("Game.GameCurrentScene.SceneValues[str_txt]"):setValue(VValueString, "")
     getObject("Game.GameCurrentScene.SceneValues[str_question]"):setValue(VValueString, "")
     getObject("Conditions[key_input_active]"):setValue(VConditionValue, false)
    end
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26

    I tried to copy the script to my game... but it doesnt seem to work. The background narration action is working, but it doesnt show any characters. See attached. 

    Key Killer

    598 Posts


  • #2, by ke4Monday, 01. May 2017, 19:40 3 years ago
    Depends on if you want it through keyboard or mouse & buttons. If Keyboard you'll have to type an eventHandler for that.

    You would also need a string where you will store the data and then an object text where it would be displayed.

    A simple eventHandler example:

    function keyboardHandler(eventType, character, keycode, modifiers)
     if eventType==eEvtKeyTextInput then
      Values["password"].String = Values["password"].String .. character
     elseif eventType == eEvtKeyDown and keycode == 8 then
      Values["password"].String = string.sub(Values["password"].String, 1, -2)
     end
     startAction("Scenes[sceneName].SceneActions[refresh]")
     return false
    end

    registerEventHandler("keyEvent", "keyboardHandler")
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11

    Where refresh is a called by other action which displays the object text to update it. If you need it limited to 10 characters you would also need to add this to the script.

    The script i posted above will add the typed character to the string if the pushed key is not a backspace, in that case it will delete the last character. At the end it will call an action which updates the object text.

    Key Killer

    810 Posts

  • #3, by afrlmeMonday, 01. May 2017, 20:34 3 years ago
    I created that key input demo as an example before we had the key input event handler (Lua).

    As ke4 says, it depends on whether you want to use some onscreen keyboard you create or allow players to type on their actual keyboard or both. On screen keyboard is a lot of work as you would have to create images, a scene object for each, polygon, actions & so on. Took me about 3 days or so to create that key input demo, which is annoying as you can write a Lua script now in less than 5 minutes that does the same thing!

    Imperator

    6842 Posts

  • #4, by sebastianMonday, 01. May 2017, 20:47 3 years ago
    You need to create An Action (called by other action) where it has some display object text with a ValueString set to let the Content of this Value be displayed on Screen:

    display object text : < vs = password ><vs=password></vs=password></div>

    When starting the visual password field just call this action.

    Also set a condition which enables the key input: "key_input" to TRUE

    make a script in the script workspace , set it as definition script and paste the following:


    (had to use external site because the greater/less than symbols get chopped here.

    EDIT: oh, too late. Ke4 was faster grin - 1 hour xD (I added an max 10 chars condition though)

    Thread Captain

    2337 Posts

  • #5, by ke4Monday, 01. May 2017, 20:47 3 years ago
    Would be also nice to have a cursor animation at the end of the string, don't know how to achieve that though. Maybe it's possible to calc the width based on  the current characters and position the cursor animation based on that? Or maybe always add and delete a ¦character in a loop at the end of the string.

    Key Killer

    810 Posts

  • #6, by sebastianMonday, 01. May 2017, 20:50 3 years ago
    Would be also nice to have a cursor animation at the end of the string, don't know how to achieve that though. Maybe it's possible to calc the width based on current character and position the cursor animation based on that? Or maybe always add and delete a ¦character in a loop at the end of the string.

    I did it for my game. Just loop ad different called by action part with the display text with and without the "_" behind it : VIDEO : https://cl.ly/1U3y2N040N2s

    Thread Captain

    2337 Posts

  • #7, by ke4Monday, 01. May 2017, 20:51 3 years ago
    Ah okay seems to be simpler than i expected razz

    Key Killer

    810 Posts

  • #8, by afrlmeMonday, 01. May 2017, 21:42 3 years ago
    Ah okay seems to be simpler than i expected razz
    Aye mate, not that hard with a looping action block as you can just toggle between 2 different display object text or display narration text actions, with one that contains the _ or | thing or whatever you want it to flash at the end of the string. I know I had it do that in the demo thing I created, but it's so long ago that I created that, that I don't remember how I sorted it out.

    Imperator

    6842 Posts

  • #9, by marvelMonday, 01. May 2017, 23:32 3 years ago
    Sebastian, do I have to add the condition "key_input" and the value "password" on the room with the password field?

    What if I have several values called "password" in the game? Isn't it going to collide?

    Key Killer

    598 Posts

  • #10, by afrlmeMonday, 01. May 2017, 23:44 3 years ago
    Sebastian, do I have to add the condition "key_input" and the value "password" on the room with the password field?

    What if I have several values called "password" in the game? Isn't it going to collide?
    Yes, it would create issues if you have multiple values/conditions with same name. You can get around that though by linking directly to the scene the value is on.
    game.CurrentScene.SceneValues["password"].String
    1

    ... which would only affect a value called password inside of the currently displayed scenes values tab.
    function keyboardHandler(eventType, character, keycode, modifiers)
      if Conditions["key_input"].ConditionValue then
        if eventType == eEvtKeyTextInput and string.len(game.CurrentScene.SceneValues["password"].String)  0 then
          game.CurrentScene.SceneValues["password"].String = string.sub(game.CurrentScene.SceneValues["password"].String, 1, -2)   
        end
        startAction(Actions["some_action_for_sound_effect"])
        startAction(Actions["your_called_by_other_action_to_refresh_the_text_again"])
      end
      return false
    end
    registerEventHandler("keyEvent", "keyboardHandler")
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11

    ... based on the function in the hastebin thing Sebastian shared.

    * edit: haha. Sebastian is correct. VS forum is messing up the code block. Deleting/replacing certain symbols.

    Imperator

    6842 Posts

  • #11, by sebastianTuesday, 02. May 2017, 06:32 3 years ago
    @marvel: 
    instead of deleting less than and greater than here in the forums you should replace them by < and >
    ( & lt ; and & gt ; ) 

    Thread Captain

    2337 Posts

Write post