change the object name

  • #1, by gustyMonday, 02. December 2013, 08:43 7 years ago
    I'm wondering, what is the actionpart for changing the object name (action text) when a player moves the cursor over object? I would like to change the action text via condition but I can't find an appropriate actionpart for that. Any thoughts?

    Forum Fan

    159 Posts


  • #2, by AlexMonday, 02. December 2013, 13:25 7 years ago
    why do you want to do that? the object name is automatically displayed in the action text when the cursor moves over the object. There is no way to change the object name itself (except with Lua, but it is not recommended, because a changed object name is not stored in savegames). Usually you'd want to activate another object (with a different name, e.g. open/closed door) which is done by changing a condition.

    Great Poster

    378 Posts

  • #3, by gustyMonday, 02. December 2013, 16:03 7 years ago
    Well, it's a common thing in adventure games. For objects and even characters.. Let say there is NPC character in the scene, but you don't know his name yet so the action text says "a man". Now you would talk to him and you would find out that his name is Robert. So from now on when a player moves the cursor over this character, action text "Robert" appears instead of "a man". Too bad this is not possible roll

    Forum Fan

    159 Posts

  • #4, by afrlmeMonday, 02. December 2013, 17:22 7 years ago
    you could do it backwards so to speak...

    name it what it should be & then use Lua to change it to the initial value.

    if you liked you could even create on mouse over action parts for the object to check if x condition is true or false & if the character or object name does not already equal something then change the name with Lua... this of course requires a bit of extra work from you but as we say: there's always a work around method for achieving what you want to do.

    for instance inside of a mouse over action you could add an if query to check if x condition or value equals something then execute one script or another which checks if the current name of the object equals x & if not then rename it.

    check attached screenshot for a quick example...
    I can't tell you if it works or not as I haven't tested it.

    Imperator

    6815 Posts

  • #5, by AlexMonday, 02. December 2013, 17:23 7 years ago
    I see. why don't you create another object which is linked to a condition, e.g. "talked to man". When the condition is true, the object is displayed and shows the text "Robert". The object polygon is the same as the other object ("a man"), but the object is placed above in the object list.

    You could still change the object name itself in a Lua script, but you have to make sure to adapt the manually changed object names when loading a savegame (or when entering the scene etc. where the changed object name is visible).

    Great Poster

    378 Posts

  • #6, by afrlmeMonday, 02. December 2013, 17:24 7 years ago
    hmm strange it has added the attachment to your first post & I didn't realize it had so I've attached twice razz

    Imperator

    6815 Posts

  • #7, by AlexMonday, 02. December 2013, 17:36 7 years ago
    here is a sample script to change the object name:
    local obj = getObject('Scenes[First scene].SceneObjects[Rock]')
    local texts = obj:getLink(VObjectName):getLinks(VTextAll)
    for i=1,table.maxn(texts) do
    local text = texts[i]
    local lang = text:getLink(VTextLanguageLanguage)
    if lang:getName() == 'Deutsch' then
    text:setValue(VTextLanguageText, 'Stein mit Zeichnung')
    elseif lang:getName() == 'English' then
    text:setValue(VTextLanguageText, 'Rock with painting')
    end
    end
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12

    I haven't tested the script, iterating the language texts can be found here as well:
    http://www.visionaire-studio.net/forum/thread/getting-an-obj...

    it's probably easier to do it without scripting but in the end it's up to you.

    Great Poster

    378 Posts

  • #8, by gustyTuesday, 03. December 2013, 07:49 7 years ago
    Thanks a lot, I wil try it smile

    Forum Fan

    159 Posts

  • #9, by afrlmeTuesday, 03. December 2013, 14:24 7 years ago
    Thanks a lot, I wil try it smile


    the script Alex posted works but you will need to edit it slightly for what you are wanting it to do.

    you will need to add an if query to check a condition or value to determine if the unknown name or the actual name should be displayed.

    I was going to suggest that a global script could be made so that you don't have to add the entire script to each object, character that requires name changes but the multiple language thing complicates matters & if you were to support multiple languages for your game then you would need to create tables to store the unknown & actual names & thus it would probably be simpler to add the full script to each object, character & item etc. oh well.

    tblObj = {} -- create an empty table
    tblObj["_temporary_"] = "" -- set table to temporary
    tblObj["obj"] = game:getLink(VGameSavedObject) -- store saved object
    tblObj["texts"] = tblObj["obj"]:getLink(VObjectName):getLinks(VTextAll) -- store all names of object
    tblObj["cond"] = getObject("Conditions[add condition name here]"):getBool(VConditionValue) -- get bool value of condition

    for i=1,table.maxn(tblObj["texts"]) do -- for each name found do...
    tblObj["name"] = tblObj["texts"][i] -- set current name based on current index value
    tblObj["lang"] = tblObj["name"]:getLink(VTextLanguageLanguage) -- check which game language is being used
    if tblObj["cond"] then -- if condition is true do...
    if tblObj["lang"]:getName() == 'Deutsch' then tblObj["name"]:setValue(VTextLanguageText, 'Stein mit Zeichnung') end
    if tblObj["lang"]:getName() == 'English' then tblObj["name"]:setValue(VTextLanguageText, 'Rock with painting') end
    else -- if condition is false do...
    if tblObj["lang"]:getName() == 'Deutsch' then tblObj["name"]:setValue(VTextLanguageText, '???') end
    if tblObj["lang"]:getName() == 'English' then tblObj["name"]:setValue(VTextLanguageText, 'something er rock like') end
    end
    end -- end for loop
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18


    on mouse over you add action part to save object to memory & then add this script (above) inside of an execute a script action... you will need to change the condition name & the text values obviously to whatever they need to be. you also need to add a clear object from memory action part to a mouse out action... you could of course directly link to the object like Alex did in the script he provided via getObject.

    I have tested the script I have just provided by setting up some key input options so I could quickly change the condition value & game language.

    Imperator

    6815 Posts

  • #10, by AlexTuesday, 03. December 2013, 14:52 7 years ago
    looks good. But why do you create the global tblObj?
    I'd recommend to use local variables instead, it's also easier to read. e.g.

    local obj = game:getLink(VGameSavedObject)
    local texts = tblObj["obj"]:getLink(VObjectName):getLinks(VTextAll)
    local cond = getObject("Conditions[add condition name here]"):getBool(VConditionValue)
    1
    2
    3
    4

    instead of
    tblObj["obj"] = game:getLink(VGameSavedObject) -- store saved object
    tblObj["texts"] = tblObj["obj"]:getLink(VObjectName):getLinks(VTextAll) -- store all names of object
    tblObj["cond"] = getObject("Conditions[add condition name here]"):getBool(VConditionValue) -- get bool value of condition
    1
    2
    3
    4


    If you have multiple objects where the text changes it makes sense to put this into a function in a global script, add parameters for the condition name and old/new text, then just call this function in the mouse over action. As AFRLme mentioned it gets more complicated if you support multiple languages.

    Great Poster

    378 Posts

  • #11, by afrlmeTuesday, 03. December 2013, 17:00 7 years ago
    I just prefer temporary tables instead of local variables...
    & aye I know that local/global variables are easier to read.

    I was told that each time you call a local variable that a new entry is created in a table as opposed to the old entry being overwritten, so if you were using this inside of a mainLoop for example or it is something that could potentially be used a lot & you don't need to store the data then it makes sense to add inside of a temporary table no? they can use local or global variables if they prefer wink

    I started writing a global script but then stopped when I realized that multiple languages would be an issue & that the only logical way to do that would be to use tables containing the actual & unknown names.

    Imperator

    6815 Posts

Write post