Changing character's name

  • #1, by ke4Sunday, 22. March 2015, 10:15 5 years ago
    Hi,

    i still don't fully understand how to use Visionaire data structure. I would like to change the name of the character.
    getObject("Characters[name]"):setValue(VCharacterName, "new name")
    1
    2


    This line of code doesn't work. Please, what i need to change to change the character's name?
    Thanks!

    Key Killer

    810 Posts


  • #2, by afrlmeSunday, 22. March 2015, 14:40 5 years ago
    It won't remember the characters name the next time you load the game as it doesn't save that field to the save game files.

    To change a name you have to use one of the text fields. VCharacterName on its own will not work because the Character has multiple language fields in which you can write different names.

    Add this to script section as a definition script...
    local texts -- empty variables

    -- * function used to update name of specified object, character, etc * --
    function setText(obj, txt)
    texts = obj.TextTextLanguages
    -- + --
    for i = 1, #texts do
    if texts[i].language == game.StandardLanguage:getId().id then
    texts[i].text = txt; obj.TextTextLanguages = texts
    break
    end
    end
    end
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14

    To use, create an execute a script containing something like this...
    -- shorthand (character)
    setText( Characters["Tom"].CharacterName, "Tommy" )

    -- longhand (character)
    setText( getObject("Characters[Tom].CharacterName"), "Tommy" )

    -- shorthand (object) [global linking]
    setText( Objects["ball"].ObjectName, "football" )

    -- shorthand (object) [direct linking] -- won't work in current public build
    setText( game.CurrentScene.SceneObjects["ball"].ObjectName, "football" )

    -- longhand (object) [global linking]
    setText( getObject("Objects[ball].ObjectName"), "football" )

    -- longhand (object) [direct linking]
    setText( getObject("Game.GameCurrentScene.SceneObjects[ball].ObjectName"), "football" )
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18

    ... should be enough to let you get on with it, methinks. wink

    Imperator

    6804 Posts

  • #3, by ke4Sunday, 22. March 2015, 15:09 5 years ago
    It's more complicated than i expected. Thanks for that!
    I don't understand to this part, what does #texts represents?

    for i = 1, #texts do
    if texts[i].language == game.StandardLanguage:getId().id then
    texts[i].text = txt; obj.TextTextLanguages = texts
    1
    2
    3
    4

    Key Killer

    810 Posts

  • #4, by SimonSSunday, 22. March 2015, 15:27 5 years ago
    #texts means size of texts. So it's a loop over all objects in texts.

    Thread Captain

    1333 Posts

  • #5, by afrlmeSunday, 22. March 2015, 15:27 5 years ago
    # is the shorter equivalent of table.maxn(table name). It returns the total table entries found in variable / table texts.

    #table_name, #(table_name) or table.maxn(table_name) are all valid methods for returning total entries in a table.

    Imperator

    6804 Posts

  • #6, by ke4Sunday, 22. March 2015, 15:34 5 years ago
    Okey, thanks for help :-)

    Key Killer

    810 Posts

Write post