Speaker text with static position

  • #1, by spacepawWednesday, 09. November 2011, 00:01 13 years ago
    Hello, after fighting for the whole day I finally managed to make speaker text into narrator text that always displays in the same part of the screen. It doesnt need invisible characters or anything like that. Also it's easy to modify so using normal speaker text is still possible (for example with one more if statement that checks for the font used you can only treat one font as narrator text and others like normal speaker text). The text is displayed in top middle part of the window (easy to change as well). Here's the code:

    
    function OnStartText(text)
       if  text:getLink(VTextOwner):isEmpty() then
            local finalPoint=game:getPoint(VGameScrollPosition)
            finalPoint.x=finalPoint.x + game:getPoint(VGameWindowResolution).x/2
            text:setValue(VTextPosition, finalPoint)
            isNarratorText=true
            narratorText=text
        end
    end

    function OnStopText(text) if text:getLink(VTextOwner):isEmpty() then isNarratorText=false end end

    function OnMainLoop() if isNarratorText then if not((game:getInt(VGameScrollDirectionHorizontal)==0) and (game:getInt(VGameScrollDirectionVertical))==0) then local finalPoint=game:getPoint(VGameScrollPosition) finalPoint.x=finalPoint.x + game:getPoint(VGameWindowResolution).x/2 narratorText:setValue(VTextPosition, finalPoint) end end end

    registerEventHandler("textStarted","OnStartText") registerEventHandler("textStopped","OnStopText") registerEventHandler("mainLoop", "OnMainLoop")

    The main loop code makes sure that the text stays in place even if the room is scrolling.

    Hope you like it smile if you have problems with making it work or modifying it let me know. I can post some variations smile

    Cheers SpacePaw

    Newbie

    0 Posts


  • #2, by EinzelkämpferWednesday, 09. November 2011, 12:08 13 years ago
    Great. Thanks for sharing. This may come in handy.

    If you use the "GameWindowResolution" field you could make the script resolution independent, instead of hardcoding the 640px width.

    Newbie

    81 Posts

  • #3, by spacepawWednesday, 09. November 2011, 14:58 13 years ago
    If you use the "GameWindowResolution" field you could make the script resolution independent, instead of hardcoding the 640px width.

    Absolutely right - modified the code above so it's universal now smile I'm not used to visionaire data structure yet smile

    Newbie

    0 Posts

  • #4, by SCUD24Friday, 11. November 2011, 02:43 13 years ago
    Nice. Thanks for taking the time to share this.

    Newbie

    28 Posts

  • #5, by afrlmeMonday, 31. December 2012, 21:03 12 years ago
    ahh sod the registerHookFunction razz

    nice one man - saved me some time from trying to figure out how to use it from the - not so clear - syntax example.

    well your script wasn't exactly clear how to use either but I've re-written it slightly & added notes to it to make it easier to understand.

    pastebin - nice & color coded & all that jazzy stuff!

    simple things first ...

    go into the "Game" options panel & set "speaker text alignment to "centered" ... * quick note as mentioned above displayed text displays the first font found in the font list ... + unless you declare it I guess?

    to use the narrator script ...

    select action part > miscellaneous > display text ... add text. * if you want to be able to scroll/perform other actions then check the "show as background text" box ... + background text can not be skipped!

    
    --[[
    narrator text position script by Spacepaw
    modified by AFRLme
    -- * --
    script type: definition
    -- * --
    define absolute position of speaker text!
    -- * usuage * --
    in the editor set: game > speaker text alignment to "centered"!
    then to display text: select action part > misc > display text > add text to display!
    if you want to be able to walk about & do other things while narrator text is visible then ...
    check the "show as background text" box!
    only downfall to background text is you can't skip it! 
    --]]

    -- * this gets & declares the x, y position of the speaker text * -- function OnStartText(text) if text:getLink(VTextOwner):isEmpty() then local finalPoint=game:getPoint(VGameScrollPosition) finalPoint.x = finalPoint.x + game:getPoint(VGameWindowResolution).x / 2 -- declares game resolution x /shared by 2 to get center! finalPoint.y = finalPoint.y + game:getPoint(VGameWindowResolution).y - 100 -- declares game resolution y (bottom) change - 100 offset to whatever you want! text:setValue(VTextPosition, finalPoint) isNarratorText=true narratorText=text print('xPos=' .. finalPoint.x .. ' yPos=' .. finalPoint.y .. ' onStart!') -- prints the x,y position values to the log! end end

    -- * kills the loop when the text has finished displaying - I think? * -- function OnStopText(text) if text:getLink(VTextOwner):isEmpty() then isNarratorText=false end end

    -- * loop to keep the displayed text in the same position on screen scroll * -- function OnMainLoop() if isNarratorText then if not((game:getInt(VGameScrollDirectionHorizontal)==0) and (game:getInt(VGameScrollDirectionVertical))==0) then local finalPoint=game:getPoint(VGameScrollPosition) finalPoint.x = finalPoint.x + game:getPoint(VGameWindowResolution).x / 2 finalPoint.y = finalPoint.y + game:getPoint(VGameWindowResolution).y - 100 narratorText:setValue(VTextPosition, finalPoint) print('xPos=' .. finalPoint.x .. ' yPos=' .. finalPoint.y .. ' onMain!') -- prints the x,y position values to the log! end end end

    registerEventHandler("textStarted","OnStartText") registerEventHandler("textStopped","OnStopText") registerEventHandler("mainLoop", "OnMainLoop")

    Imperator

    7278 Posts

  • #6, by cargo1983Tuesday, 01. January 2013, 00:30 12 years ago
    Thank you very much, this is exactly what I was after. Really appreciate it!!

    Newbie

    0 Posts

  • #7, by MilenaTuesday, 01. January 2013, 19:00 12 years ago
    Sorry, my english is not so good, but where does this script must be included, must it be executed by an action (and if yes, from where?) or replaces it an original script? I hope my question is not too stupid grin (I fear, however, it is wink), but that's became not clear to me.

    Newbie

    74 Posts

  • #8, by afrlmeTuesday, 01. January 2013, 20:21 12 years ago
    ahh right ...

    in the script area of the Visionaire Studio editor > create a new script & in the properties tab set the script type to "definition" (not sure what it's called in German but it's the option on the right hand side)

    then copy/paste the code above into the script.

    see if you can work out the rest from the attachments I added ...

    this script automatically positions displayed text only (does not position displayed text by characters but I think it shouldn't be too hard to edit this to include both - will look into it sometime in the future)

    Imperator

    7278 Posts

  • #9, by Yug_EtsapMonday, 27. January 2014, 00:57 11 years ago
    Is there any way this script could be applied to other text displays? Specifically - dialogs? I'm guessing getting rid of the talk animation is also going to be problematic there, though.

    Just to clarify - I'm making an adventure game/visual novel hybrid and I need all the text to go into a textbox on the bottom of the screen. Being able to use the dialog feature would greatly help me, instead of having to script out the entire dialogs in the action parts.

    Newbie

    12 Posts

  • #10, by afrlmeMonday, 27. January 2014, 01:22 11 years ago
    if you don't add any animations to the character talk animation then nothing will be triggered... you can add them to character animations instead which allows you to manually trigger & control them as needed.

    & yes the script can be adapted for spoken text too - I think the info was mentioned in the first post?

    Imperator

    7278 Posts

  • #11, by Yug_EtsapMonday, 27. January 2014, 01:51 11 years ago
    I'm sorry, it could be my scripting ineptitude showing, but I see nothing about getting the script to work with the dialog feature. I just see him mention you can have both narrator text and regular speaker text by adding an if statement checking for the font.

    Newbie

    12 Posts