DE EN FR ES IT CZ
Back Back to top

Changing the name of an object

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

  • #1, by elwan 7 years ago Quote
    Is it possible with Lua to change, anytime during the game, the name included in the properties tab of an object ?
    Thanks for helping...

  • New to Visionaire Studio?

    Create point and click adventures without coding. The free version covers up to 25 scenes per project. For more scenes or to earn money with your game, you need a license.

    See the Indie Bundle Try it for free
  • #2, by afrlme 7 years ago Quote
    Yes it is, but unfortunately the new name doesn't get saved into the save game data, meaning that when someone loads a save game that the original name will be displayed instead. However you work around this by creating a value & saving the name to the string section of the value & then on mouse over the character you can use Lua to overwrite the name with the one stored in the value & that way it will always display the correct name.

    I've just woken up, but I'll dig out the script/function to do that for you later on. wink
  • #3, by elwan 7 years ago Quote
    Thank you for this quick answer!
    I'll wait for your script, but I have to mention that I am a beginner in Lua...
  • #4, by afrlme 7 years ago Quote
    Ok, so here's what you can do...

    1. add this as a definition type script in the script section of the editor.

    function changeName(txt)
    
    
    
        local obj = game.CurrentObject.Name.TextLanguages
    
        -- + --
    
        for i = 1, #obj do
    
          obj[i].text = txt
    
        end
    
        -- + --
    
        game.CurrentObject.Name.TextLanguages = obj
    
    
    
    end


    Now what you need to do is create some mouse over actions for the objects/characters that you want to change the name for.

    & inside of these you need to add something like this...

    if value "example" is 1
    execute a script >


    local t = {
    
     English = "original name",
    
     German = "ursprüngliche name"
    
    }
    
    
    
    changeName( t[ game.StandardLanguage:getName() ] )

    else if value "example" is 2

    local t = {
    
    English = "alternative name",
    
    German = "alternativer name"
    
    }
    
    
    
    changeName( t[ game.StandardLanguage:getName() ] )


    end if

    ----

    Hopefully what I've just written makes sense.
    Anyway, good luck. wink

    * edit: I should have probably explained how it works. The definition script is a function that allows us to change the name of whatever the cursor is currently hovering over for each available game language. The mouse actions you create expect you to use a value that you can query to check which name it should use & then inside of some execute a script action parts you create some temporary tables containing the name for each available language & then the engine picks the relevant name from the table based on the current active game language & updates the name to that.
  • #5, by elwan 7 years ago Quote
    Thank you again for the quality of the answer.
    It will take me some time to implement this code in my game as I already said I am not an expert...
  • #6, by afrlme 7 years ago Quote
    No problem.

    What I posted is more or less plug & play. Just need to edit the table values & maybe the name of the languages if they don't match up - everything is case sensitive when it comes to Lua script.