[SOLVED] lua scripting: how can the player input a text in a textbox?

  • #1, by andy-rinaldiWednesday, 03. September 2014, 17:49 10 years ago
    Hi lua expert wink
    The player of my game needs to input a text in a login/password fields. How can do it with Visionaire and lua?
    I was thinking to use the Key Action feature, when the player press a key, the value is saved in a variable. When the player press the second key, the variable string becomes "variable + variable" where the first variable is the first key pressed and the second variable is the second key pressed etc.. You know what I mean?

    Something like:

    local strTextbox

    strTextbox = getObject("Values[strFirstKey]")
    strTextbox = strTextbox + getObject("Values[strSecondKey]")

    With a loop I suppose.

    Thank you.

    Forum Fan

    160 Posts

  • #2, by afrlmeWednesday, 03. September 2014, 19:51 10 years ago
    Wouldn't need to use a loop.

    Just a basic count variable which adds a key to a table & then returns the them as a string when player presses enter or the send button whatever & checks if the return result equals the same.

    You would need to do the key input part though... but should only have it trigger on key (released) so that it only performs the function once after key has been released as opposed to millions of times while the key is being held down.

    main script (definition)
    local result = "" -- create an empty string
    -- * function for adding text to end of variable * --
    function inputChar(c)
     result = result .. c -- add text to end of result
    -- * function which compares the string value of the result variable with the string value you include with the function * --
    function checkInput(r)
     if r == result then print("true") else print("false") end
     result = "" -- reset result back to default value

    to add a new string character...
    inputChar("a") -- adds a to the variable

    to check if variable equals something...
    checkInput("tom") -- checks if variable returns tom

    We could get more complicated than this by using tables so that we can generate an index key value to limit amount of characters that can be entered etc & we could also extend the checkInput function so that it performs a specified action based on whether it returns true or false & so on.


    7283 Posts

  • #3, by brut69Wednesday, 03. September 2014, 22:16 10 years ago
    Thanks , this could be useful for me

    Great Poster

    266 Posts

  • #4, by andy-rinaldiWednesday, 03. September 2014, 22:30 10 years ago
    Thank you but could you please explain me better?
    For example:
    result = result .. c (?)

    I know to get a variable from Visionaire using getObject but I don't see it in your script.
    Can you show me a real example with Visionaire Object Model?

    I think you use the script in a lua editor but I'll like look it in Visionaire...

    I get the variable from key action on game setting...
    key action -> press A key (released) -> set value (how can I set a string value?)

    Many many many thanks for your patience. red

    Forum Fan

    160 Posts

  • #5, by SimonSWednesday, 03. September 2014, 23:13 10 years ago
    Strings in lua can't be added, you need to use the concatenate operator (+ is a operator, concatenate is putting a string together), that operator has 2 points, so "result .. c" is result and c.

    The next version holds some changes to the object model, but the old writing will stay compatible.
    For getting values, in the upcoming version you can write


    If you want to write something there it's

    getObject("Values[name]"):setValue(VValueString, "")

    Now let's get a string, concatenate something and save it back.

    local obj = getObject("Values[name]")
    local str = obj:getStr(VValueString)
    str = str.."_test"
    obj:setValue(VValueString, str)

    In the upcoming version this will also work:

    Values.name.String = Values.name.String.."_test"

    Thread Captain

    1582 Posts

  • #6, by afrlmeThursday, 04. September 2014, 02:02 10 years ago
    Yeah sorry... I was just giving a quick example without bothering to comment what each thing did.

    result = result .. c

    ... c was the string character we added. So let's say we did:

    ...then we added "a" to the end of whatever already existed in the variable "result".

    "result" was defined as an empty variable at the beginning & also it gets set back to an empty variable whenever you check if the variable equals whatever you wanted to check it against.

    quick working example:
    inputChar("y"); inputChar("e"); inputChar("s") -- we've just added string "yes" to result variable

    ...now let's see if it returns true for "yes"
    checkInput("yes") -- if result = yes then do some action else do some negative action


    7283 Posts

  • #7, by andy-rinaldiThursday, 04. September 2014, 18:34 10 years ago
    Strings in lua can't be added, you need to use the concatenate operator (+ is a operator, concatenate is putting a string together), that operator has 2 points, so "result .. c" is result and c.

    AHHHH, this is the first time that I see 2 points as concatenate operator, I was thinking in + symbol as in C-like languages! shock

    I think I have understood now but how can I save the string value in a variable "value" in the key action tab? I can only set the value as number and not as string... can you explain me?


    Forum Fan

    160 Posts

  • #8, by SimonSThursday, 04. September 2014, 18:58 10 years ago
    A value always holds an int (VValueInt) and a string (VValueString).

    local result = ""
    getObject("Values[value]"):setValue(VValueString, result)

    If want to save it in the key actions tab, you need to use the script action part.

    Thread Captain

    1582 Posts

  • #9, by andy-rinaldiThursday, 04. September 2014, 22:29 10 years ago
    Ok, but my question is which value I should set in key action tab?
    I can't set a string value.

    I have A (released) then value variable= ??? (I can put only numbers here) then call script


    Forum Fan

    160 Posts

  • #10, by afrlmeThursday, 04. September 2014, 22:33 10 years ago
    I'll get around to adding more stuff to my beginners guide to lua thing, when I get back to spain, next week sometime.

    As Simon said: you can only save string values to an actual vs value using lua script as there's currently no text input box for setting a string value with action parts. I don't really see much point in using values though as the key input is temporary & thus could technically even use a temporary table to save the input value, if you felt inclined to do so...

    I was considering adding a script & some instructions to the wiki for key input sequences, next week. If I don't do that within a couple weeks then remind me, as I will have probably forgotten! grin (terrible memory)


    7283 Posts

  • #11, by andy-rinaldiFriday, 05. September 2014, 00:38 10 years ago
    Ok, thanks a lot. I can wait the next week.

    Forum Fan

    160 Posts