Dialogue box question

  • #10, by afrlmeTuesday, 23. February 2021, 01:09 3 years ago
    Only one instance of the textStarted & textStopped event handlers can exist per project. You will need to merge one script into the other, or alternatively manually call the functions inside of the event handler functions belonging to the speech bubble script. What I'm saying probably doesn't make a lot of sense & it's kind of difficult for me to explain what I mean in a few words.

    Imperator

    7278 Posts


  • #11, by jf-mFriday, 19. March 2021, 13:37 3 years ago
    Hi again!

    I was wondering if i can position my texte in the absolute.
    I mean: i have the dialog portrait script, the setTextPosHook function. It is working fine as long as my background is the same resolution than in my game's properties. If i use an larger background, the text is not in the right position. It is always in the VTextPosition i put in the script. I tried to modify those values, using %, but it didn't work.
    Is there a way to center the text in the current screen, not in the whole background?
    Thanks for any help!

    Newbie

    39 Posts

  • #12, by afrlmeFriday, 19. March 2021, 13:53 3 years ago
    Yeah, you need to take the current scroll position of the scene into account. Here's an example of the setTextPosition hook that also includes the scroll position:

    function setTxtPos(text)
    
      if text.Owner:getId().tableId == eCharacters  then
    
        text.Position = {x = game.ScrollPosition.x + 100, y = game.ScrollPosition.y + 900}
    
        return true
    
      end
    
      return false
    
    end
    
    
    
    registerHookFunction("setTextPosition", "setTxtPos")


    Change the 100 & 900 bits to wherever you want to offset the text to in the current viewport. If you want to horizontally center the text in the center of the screen then replace 100 with:
    (game.WindowResolution / 2)


    Imperator

    7278 Posts

  • #13, by jf-mFriday, 19. March 2021, 14:10 3 years ago
    Thanks for your answer!

    I didn't succed in using (game.WindowResolution / 2), but it doed the work with your first code!

    You rock!! smile



    Newbie

    39 Posts

  • #14, by afrlmeFriday, 19. March 2021, 18:59 3 years ago
    Sorry, I made a typo.

    (game.WindowResolution.x / 2)

    Imperator

    7278 Posts

  • #15, by gregor-muellerWednesday, 04. August 2021, 12:37 2 years ago
    Sorry for bringing this up again, after this has been explained so well.
    I am using the code suggested by afrlme and it is working a treat. But I have gone ahead and made my life very complicated: I have added an outfit for one of the characters where he has a hat and one without the hat.
    Since I have no knowlegde of Lua I wanted to ask if anyone knows how I can add a request to check which costume is being worn and show the according picture. Any help would be greatly appreciated!

    Newbie

    20 Posts

  • #16, by afrlmeWednesday, 04. August 2021, 14:01 2 years ago
    -- * table to store character names & portrait_index value (case sensitive) * --
    
    local portraits = {
    
    
    
    ["Tom"] = 1,
    
    ["Barry"] = 2,
    
    ["Angela"] = 4
    
    
    
    }
    
    
    
    -- * text started event listener * --
    
    function sText(text)
    
    
    
     if text.Owner:getId().tableId == eCharacters then -- check text belongs to a character
    
    
    
         Interfaces["dialog_portraits"].Visible = true -- show the dialog_portraits interface
    
         if text.Owner == Characters["Barry"] then
    
          if characters["barry"].CurrentOutfit:getName() == "example" then
    
            Values["portrait_index"].Int = 2
          else
    
            Values["portrait_index"].Int = 3
    
          end
    
        else
    
          Values["portrait_index"].Int = portraits[ text.Owner:getName() ] -- specify which character portrait to show
    
        end
    
    
    
     end
    
    
    
    end
    
    
    
    -- * text finished event handler * --
    
    function eText(text)
    
    
    
     if text.Owner:getId().tableId == eCharacters then -- check text belongs to a character
    
    
    
         Values["portrait_index"].Int = -1 -- reset portrait_index value back to -1 to hide all portrait images
    
         Interfaces["dialog_portraits"].Visible = false -- hide the dialog_portraits interface
    
    
    
     end
    
    
    
    end
    
    
    
    -- * event handlers * --
    
    registerEventHandler("textStarted", "sText") -- event handler for begin text
    
    registerEventHandler("textStopped", "eText") -- event handler for end text

    Imperator

    7278 Posts

  • #17, by afrlmeWednesday, 04. August 2021, 14:09 2 years ago
    I'll not edit the post above as it might mess up the code - this forum cms does weird things every now & then.

    Anyway, there's multiple methods you could use for this as you could have created each outfit as a unique character, or maybe you want to create mood based static/animated portraits for each of the characters to show when they are neutral, angry, sad, etc.

    The code & tables could technically be rewritten to work in multiple ways, such as you assign a value to the character itself to specify which mood they are in & then you use that to determine which portrait should be shown. Having said that, I'm not going to go into showing examples of how to achieve that right now.

    Imperator

    7278 Posts

  • #18, by red363Thursday, 02. September 2021, 00:16 2 years ago
    Hi.
    Thanks a lot for the great script.

    You can tell what needs to be added to this script so that it controls not only the display of the interface, but also shows the character during his reply and hides it at the end of his reply?
    Like "Characters [...]. CharacterActive = true / false"

    Unfortunately, at the moment I do not know LUA, so I cannot think of it myself roll

    Forum Fan

    101 Posts

  • #19, by esmeraldaThursday, 02. September 2021, 10:06 2 years ago
    This script is made to show portraits of the characters, not the characters themselves.

    I don't know the setup of your game. Are there characters in the game walking around, or is it more of a first person view and you use characters only for the dialogues?

    When using portraits, not the characters themselves: add portraits of the characters as buttons to the interface with your textbox. Assign a value for portrait_index to that button and change name and value according to your settings in the script.

    When using characters you could set the postion of the character so that it aligns with your box (but you would have to do this for every scene), leave all directions of the character empty, only add an image to the talk outfit. Then the character should appear when talking. But keep in mind, that the interface is above everything in the scene including the characters. So the characters can only be on the side, above, below the text box, not in front of it.

    Key Killer

    514 Posts

  • #20, by red363Thursday, 02. September 2021, 22:54 2 years ago
    This script is made to show portraits of the characters, not the characters themselves.

    I don't know the setup of your game. Are there characters in the game walking around, or is it more of a first person view and you use characters only for the dialogues?

    When using portraits, not the characters themselves: add portraits of the characters as buttons to the interface with your textbox. Assign a value for portrait_index to that button and change name and value according to your settings in the script.

    When using characters you could set the postion of the character so that it aligns with your box (but you would have to do this for every scene), leave all directions of the character empty, only add an image to the talk outfit. Then the character should appear when talking. But keep in mind, that the interface is above everything in the scene including the characters. So the characters can only be on the side, above, below the text box, not in front of it.
    Thank you for the answer.
    Yes, this is a first person view and I only use characters for dialogue and lines / comments.

    Thanks for the idea, I'll try the option with buttons.

    Forum Fan

    101 Posts