Changing an NPC's name label after the player finds out their real name

  • #1, by sophie-ySaturday, 29. May 2021, 17:09 3 years ago
    Hi everyone!

    I'm looking for some advice on a new problem I've come up against with my game - I'd like to change the name of my NPCs after my main character has interacted with them and found out what their name is (as in the name set in their properties that shows up when you mouse over them). E.g. having a character show up as "Fisherman", until the player has spoken to them and selected the dialogue option to ask their name, from which point they'll now show up as "Brian". Hopefully it should just be a case of creating a script, but I'm still a complete novice with Lua so I wouldn't know where to begin!

    Without scripting, the solutions I've tried so far are:

    - Creating two separate characters, one with the initial name and one with the NPC's real name. But I quickly realised that, because I want most of my dialogue options to change/disappear after being said, this required a bunch of conditions related to whether an option was still available.
    - Creating an object on the character's scene in order to draw a hotspot on top of them, with the initial label and an action part to initiate dialogue when left clicked, which then switches off after the NPC's real name is discovered by toggling a condition off. This, however, required me to draw the hotspot very carefully otherwise the real character's label would keep flashing up in areas I'd missed.

    I did find a few forum posts too. One was specifically about changing a character's name, which gives an idea of the script parts needed, but I'm not sure how to put the together ( https://www.visionaire-studio.net/forum/thread/changing-the-... ). Another couple were about changing object names, but I'm not sure how to edit the scripts to relate to character names ( https://www.visionaire-studio.net/forum/thread/change-the-ob... , https://www.visionaire-studio.net/forum/thread/changing-the-... ).

    Any help would be really appreciated!

    Newbie

    6 Posts


  • #2, by afrlmeSunday, 30. May 2021, 12:27 3 years ago
    A'llo, here is a small function I wrote a little while back that lets you change the name of pretty much anything.

    Quick note: names are not stored in the save game files but values & conditions are, so taking that into consideration it's possible to store the name inside of the string section of a value or inside of Lua tables.

    1. Go to the script section of the Visionaire Studio editor, create a new script (leave it as a definition type script) & paste this code into it

    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 

    2. Create a value on each of the characters you plan on changing the names of & in the string section type what you want their initial names to be, such as "???" or "some strange looking alien". Now rename the value(s) to "name".

    3. Now go to the actions tab for each of the characters you want to change the name of & create a cursor enters character area action & then create an execute a script action part in this & add this code to it...
    changeName(game.CurrentObject.Values["name"].String)

    4. Whenever you want to change the name of the character you just need to create an execute a script action part somewhere (in the relevant action block where you want to update the name) & then you will need to add a small line of code to change the string section of the value you created for the character...

    Characters["insert characters name here"].Values["name"].String = "insert new name here"

    Now when you hover back over the character the new name should be displayed.

    Quick note: the same changeName() function can also be used for changing the names of scene objects too, but the value method won't work for that if you plan on releasing the game with multiple language options. Instead you would need to use Lua tables/arrays to store the new names into. Here's a quick example of what you would need to include inside of an on mouse enters action for a scene object.

    if Conditions["name_known"] is true

    execute a script >
    
    
    local t = {
    
     English = "new name in english",
    
     German = "new name in german"
    
    }
    
    
    
    changeName( t[ game.StandardLanguage:getName() ] )

    end if
    The language names might need to be changed in the script, if that's not what you called them. The condition can be called whatever you want, but again make sure it's changed to whatever you call it inside of the script too.

    & a final quick note: all names are case sensitive, so make sure you type them out exactly the same as they are inside of the Visionaire Studio editor.

    P.S: I forgot to mention that you will get much faster support on our Discord server @ https://discord.gg/g5zFejW, than on here as we only check in on the forum every now & then, but are online most of time on Discord.

    Imperator

    7278 Posts

  • #3, by sophie-yMonday, 31. May 2021, 23:32 3 years ago
    Awesome, thanks so much Lee! It works perfectly smile

    Just to check I've understood correctly, with what you'd said about names not being stored in saved games, does that mean that your solution will overcome that because the script uses value strings? I would check, but adding a save menu is still on my too do list!

    And thank you in advance for the scripts for different languages - it's not a bridge we've crossed just yet, but we will be at some point!

    Newbie

    6 Posts

  • #4, by afrlmeTuesday, 01. June 2021, 00:09 3 years ago
    Yeah, the name fields for objects, characters, items, etc are not stored in the save game files. By default it always uses the names that are stored in the xml data belonging to the game files, but you can work around that by using values or tables & changing the name based on the data stored in those, everytime you mouse over whatever it is.

    Imperator

    7278 Posts

  • #5, by sophie-yTuesday, 01. June 2021, 01:38 3 years ago
    Yeah, the name fields for objects, characters, items, etc are not stored in the save game files. By default it always uses the names that are stored in the xml data belonging to the game files, but you can work around that by using values or tables & changing the name based on the data stored in those, everytime you mouse over whatever it is.

    Brilliant, thanks again!

    I've joined the Discord server now too, although I really appreciate how quickly you've gotten back to me on here as well!

    Newbie

    6 Posts