Login / Registrieren
DE EN FR ES IT CZ
Zurück Nach oben

Changing character's name

  • #1, by ke4 11 years ago Zitieren
    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")
    


    This line of code doesn't work. Please, what i need to change to change the character's name?
    Thanks!
  • #2, by afrlme 11 years ago Zitieren
    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
    

    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" )
    

    ... should be enough to let you get on with it, methinks. wink
  • #3, by ke4 11 years ago Zitieren
    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
    
  • #4, by SimonS 11 years ago Zitieren
    #texts means size of texts. So it's a loop over all objects in texts.
  • #5, by afrlme 11 years ago Zitieren
    # 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.
  • #6, by ke4 11 years ago Zitieren
    Okey, thanks for help :-)