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
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")
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.
Ah okay seems to be simpler than i expectedAye 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.
Sebastian, do I have to add the condition "key_input" and the value "password" on the room with the password field?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.What if I have several values called "password" in the game? Isn't it going to collide?
game.CurrentScene.SceneValues["password"].String
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")