Displaying Character Name along with Dialog

  • #1, by mikael32225Monday, 10. July 2017, 10:23 7 years ago
    I display all my dialog in the same area, as if watching a subtitled film, but I worry about the player missing who is doing the talking.

    Is there an easy way to display the name of the character talking?

    I basically want dialog to look like this:

                             SAM
    Hi, my name is Sam and I'm talking.


    Newbie

    42 Posts


  • #2, by sebastianMonday, 10. July 2017, 10:34 7 years ago
    the easiest way would be to write that name also in the display text action part as the first line. 
    Also im pretty sure you could enhance the Lua script youbuse to reposition the display text by adding the characters Name in feont of it... 

    what scriot did you use here? 

    Thread Captain

    2346 Posts

  • #3, by mikael32225Monday, 10. July 2017, 11:18 7 years ago
    I'm using the basic script that you pointed me to in another thread:

    -- let's create the function which sets the position of displayed text
    function setTextPosHook(text)
     -- if text owner is a character then...
     if text:getLink(VTextOwner):getId().tableId == eCharacters then
      text:setValue(VTextPosition, {x=630, y=625})
      return true
     end
    end
     
    -- let's create the event listener for handling position of displayed text
    registerHookFunction("setTextPosition", "setTextPosHook")
    I'm not very good with Lua yet, would it just be something like adding a print command?

    Newbie

    42 Posts

  • #4, by sebastianMonday, 10. July 2017, 11:32 7 years ago
    try to add these lines after or before the new position line'

    newtext = text:getLink(VTextOwner):getTextStr(VCharacterName).. "/n".. text:getTextStr(VTextCurrentText)
    
    text:setValue(VTextCurrentText, newtext)
    
    untested. 
    im not sure about that /n here.. maybe you need a normal html < br > tag... 

    Thread Captain

    2346 Posts

  • #5, by SimonSMonday, 10. July 2017, 12:16 7 years ago
    If you want to change the text, you need to use the textText Hook, looks like the rest.

    function text( obj )
      return obj.Owner.name .. "\n" .. obj.CurrentText
    end

    registerHookFunction("textText", "text")

    Thread Captain

    1580 Posts

  • #6, by mikael32225Monday, 10. July 2017, 12:40 7 years ago
    Simon, is your suggestion a separate script or should it still be combined with the positioning script?

    Newbie

    42 Posts

  • #7, by sebastianMonday, 10. July 2017, 12:42 7 years ago
    just add it under the existing script under the registerhookfunction smile 

    Thread Captain

    2346 Posts

  • #8, by SimonSMonday, 10. July 2017, 12:45 7 years ago
    It's seperate.

    Thread Captain

    1580 Posts

  • #9, by mikael32225Monday, 10. July 2017, 12:51 7 years ago
    Nothing seems to be happining. Tried both adding it below the positioning script and in a separate script.

    Newbie

    42 Posts

  • #10, by mikael32225Monday, 10. July 2017, 13:07 7 years ago
    This is what it looks like now:

    -- let's create the function which sets the position of displayed text
    function setTextPosHook(text)
     -- if text owner is a character then...
     if text:getLink(VTextOwner):getId().tableId == eCharacters then
      text:setValue(VTextPosition, {x=630, y=625})
      return true
     end
    end

    -- let's create the event listener for handling position of displayed text
    registerHookFunction("setTextPosition", "setTextPosHook")


    -- adding character name to dialog
    function text( obj )
      return obj.Owner.name .. "\n" .. obj.CurrentText
    end

    registerHookFunction("textText", "text")


    There is nothing that indicates any change. For instance the linebreak doesn't show up either. It's like it wasn't there at all.


    Newbie

    42 Posts

  • #11, by afrlmeMonday, 10. July 2017, 13:18 7 years ago
    I'm pretty sure you can't add line breaks into the text.

    Anyway, it won't do anything as you need to manually call the text function. It's not automatic.

    -- let's create the function which sets the position of displayed text
    function setTextPosHook(text)
     -- if text owner is a character then...
     if text:getLink(VTextOwner):getId().tableId == eCharacters then
      text:setValue(VTextPosition, {x=630, y=625})
      txt(game.CurrentCharacter)
      return true
     end
    end
    
    -- let's create the event listener for handling position of displayed text
    registerHookFunction("setTextPosition", "setTextPosHook")
    
    
    -- adding character name to dialog
    function txt(obj)
      return obj.Owner:getName() .. ": " .. obj.CurrentText
    end
    
    registerHookFunction("textText", "txt")
    

    Imperator

    7278 Posts