License from €75 Log in
DE EN FR ES IT CZ

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

This thread is a few years old. Some details may refer to an earlier version of Visionaire Studio. Current tutorials

  1. · 13 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.

  2. Working on a game?

    The free version covers up to 25 scenes per project. For more scenes and to sell your game, you need a license.

    See licenses Try it for free
  3. · 13 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
    end
    
    -- * 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
    end
    

    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.
  4. · 13 years ago
    Thanks , this could be useful for me
  5. · 13 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?)
    then?

    Many many many thanks for your patience. red

  6. · 13 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

    getObject("Values[name]"):getStr(VValueString)
    


    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"
    
  7. · 13 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:
    inputChar("a")
    

    ...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
    
  8. · 13 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?

    Thanks.
  9. · 13 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.
  10. · 13 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

    cry
  11. · 13 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)
  12. · 13 years ago
    Ok, thanks a lot. I can wait the next week.

This thread is closed because nobody has replied for more than a year. Feel free to ask your question in a new thread.

New thread

Really delete this post?