Dialogue box question

  • #10, by afrlmeTuesday, 23. February, 01:09 9 months 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

    7036 Posts


  • #11, by jf-mFriday, 19. March, 13:37 9 months 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

    31 Posts

  • #12, by afrlmeFriday, 19. March, 13:53 9 months 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")
    1
    2
    3
    4
    5
    6
    7
    8
    9


    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)
    1


    Imperator

    7036 Posts

  • #13, by jf-mFriday, 19. March, 14:10 9 months 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

    31 Posts

  • #14, by afrlmeFriday, 19. March, 18:59 9 months ago
    Sorry, I made a typo.

    (game.WindowResolution.x / 2)
    1

    Imperator

    7036 Posts

  • #15, by gregor-muellerWednesday, 04. August, 12:37 4 months 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

    19 Posts

  • #16, by afrlmeWednesday, 04. August, 14:01 4 months 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
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44

    Imperator

    7036 Posts

  • #17, by afrlmeWednesday, 04. August, 14:09 4 months 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

    7036 Posts

  • #18, by red363Thursday, 02. September, 00:16 3 months 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

    Newbie

    19 Posts

  • #19, by esmeraldaThursday, 02. September, 10:06 3 months 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.

    Great Poster

    439 Posts

  • #20, by red363Thursday, 02. September, 22:54 3 months 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.

    Newbie

    19 Posts

Write post