Displaying Character Name along with Dialog

  • #1, z mikael32225Monday, 10. July 2017, 10:23 hodinky 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.


    Bažant

    42 Posts


  • #2, z sebastianMonday, 10. July 2017, 10:34 hodinky 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? 

    Kapitán

    2346 Posts

  • #3, z mikael32225Monday, 10. July 2017, 11:18 hodinky 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?

    Bažant

    42 Posts

  • #4, z sebastianMonday, 10. July 2017, 11:32 hodinky 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... 

    Kapitán

    2346 Posts

  • #5, z SimonSMonday, 10. July 2017, 12:16 hodinky 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")

    Kapitán

    1582 Posts

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

    Bažant

    42 Posts

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

    Kapitán

    2346 Posts

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

    Kapitán

    1582 Posts

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

    Bažant

    42 Posts

  • #10, z mikael32225Monday, 10. July 2017, 13:07 hodinky 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.


    Bažant

    42 Posts

  • #11, z afrlmeMonday, 10. July 2017, 13:18 hodinky 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")
    

    Imperátor

    7285 Posts