display (object) text via Lua?

  • #1, z sebastianSaturday, 08. April 2017, 12:54 hodinky 8 years ago
    Aye mates,

    is there any possible way to display texts on the screen via lua. I have to display object texts depending on a selected page. Because each page has a different corresponding value string from visioanire i have to do big if/else action parts to get the page number and display its <vs=page_XX> string.
    Is there an easy way to either print object text on the screen via lua script so i can something like the following ?
    i=1
    printtext("vs=page".. i , objectname , x , y , left)

    Kapitán

    2346 Posts


  • #2, z afrlmeSaturday, 08. April 2017, 13:38 hodinky 8 years ago
    Supposedly there is a method of displaying text with Lua script using the new draw function - don't ask me how as I don't currently know. SIMON? grin

    Imperátor

    7285 Posts

  • #3, z sebastianSaturday, 08. April 2017, 18:05 hodinky 8 years ago
    I guess its already possible to manipulate the "ActiveText" structure field.
    But how do i refer properly to the already displayed (so active) text from an object. I don't see any field inside the object which links to a text field...

    The least thing i want to do is to iterate through all displayed texts which got somehow put into a table via a hook function to find the right object... unless its easyer than i think...

    Kapitán

    2346 Posts

  • #4, z afrlmeSaturday, 08. April 2017, 18:29 hodinky 8 years ago
    I'm not sure exactly what you are trying to do. Are you trying to update the text that is displayed?

    I take it the book thing is on an interface & the player can change the page & on page change you want to update the text, yes?

    If you have the object text you are using so that it's wrapped to a certain width then you could probably create a Lua table containing all of the different texts for each language & assign the relevant text to a VS value, then on page change you just need to update the string section of the value with the correct text in the table & then you update the display object text to refresh it with the new text. I can't guarantee it will work, but it's worth a try?

    * edit: it seems you can't iterate through ActiveTexts but you can use a eventHandler with textStarted to listen out for when a text belonging to object x is started. You could then update the text with TextCurrentText based on the page value.

    I ran a little test with this...
    function txtStart(text)
     if text.TextOwner:getId().tableId == eObjects then
      print( text.TextOwner:getName() )
     end
    end
    
    registerEventHandler("textStarted", "txtStart")

    & I added a couple of different object texts into the scene as well as a narration text & I assigned one of the object texts to be updated whenever I released space bar.

    Here's what my log printed...

    18:48:32: Engine Version: 4.2.5 (Build 1185 from Build date: Nov 24 2015)
    18:48:32: Time needed for preloading game: 0 msec
    18:48:32: Initializing graphics interface. Surface size: 1024x768, render size: 1024x768
    18:48:32: Using Framebuffer with texture.
    18:48:32: red, green, blue, alpha, depth size: , doublebuffer , accelerated
    18:48:32: Serialization finished. Needed time: 26 ms
    18:48:32: SetupParents finished. Needed time: 0 ms
    18:48:32: SortLinks finished. Needed time: 0 ms
    18:48:32: Interfaces loaded. Needed time: 1 ms
    18:48:32: Scripts loaded. Needed time: 0 ms
    18:48:32: Time needed for loading game: 372 msec
    18:48:33: Rock
    18:48:33: Object0
    18:48:35: Rock
    18:48:39: Rock

    & here's a screenshot of the actions I created inside of an at begin of scene action & the space bar (released) key action.

    https://i.gyazo.com/05d28970804777258689f7136de93cfa.png

    https://i.gyazo.com/58ca19ed0df409dabf9b4a387be6f86e.png

    edit: seems iteration is pretty pointless. Much simpler to use a Lua table containing various texts & insert the text based on page number into a value then display that inside of a display object text.

    Imperátor

    7285 Posts

  • #5, z sebastianSaturday, 08. April 2017, 20:22 hodinky 8 years ago
    yeah thought also about using a "temporary" value where i store the actual needed string and then use this as an output

    The plan right now is to redesign and tidy up my self written save menu which uses the autosaves and editable names for the gamestates.

    My scenario is that i list 10 items per page (5 pages), so a total of 50 gamestates.
    I use one simple display text action part to display the value strings of state 1-10 on page 1 , 11-20 on page 2 and so on:

    for page one "display object text":
    < vs=gamestate_1 > 
    < vs=gamestate_2 > 
    < vs=gamestate_3 > 
    < vs=gamestate_4 > 
    < vs=gamestate_5 > 
    < vs=gamestate_6 > 
    < vs=gamestate_7 > 
    < vs=gamestate_8 > 
    < vs=gamestate_9 > 
    < vs=gamestate_10 > 

    for page two "display object text":
    < vs=gamestate_11 > 
    < vs=gamestate_12 > 
    < vs=gamestate_13 > 
    < vs=gamestate_14 > 
    < vs=gamestate_15 > 
    < vs=gamestate_16 > 
    < vs=gamestate_17 > 
    < vs=gamestate_18 > 
    < vs=gamestate_19 > 
    < vs=gamestate_20 > 
    etc..


    When hovering one area which is located behind the string from e.g. value one (gamestate_1 or gamestate_11 or gamestate_12, etc ---the first slot on each page) it gets highlighted by switching to the active image of this field.

    The problem here is that the color of the highlight is the same as the text so i have to update only the line of the highlighted text. My solution for now was to overlay it with another object text from another object with a different font (which got previously changed via lua).
    So for every slot I have to additionally set an object text (for slot 1: gamestate_1, gamestate_11, gamestate_21, gamestate_31, gamestate_41) depending on the currently viewed page (1-5) . 

    My idea was just display text for slot 1 and then do some lua magic to edit the current text to display the content of gamestate_x where x is calculated by the page number and selected slot 1-10...

    Don't know if i described it approximately understandable enough razz

    EDIT: i guess i dont stress me and just change the highlight color to something else so i dont need to update the font and display aditional texts razz

    Kapitán

    2346 Posts

  • #6, z afrlmeSaturday, 08. April 2017, 21:12 hodinky 8 years ago
    No, sorry mate. Having a bit of a hard time following with just the text. razz

    Imperátor

    7285 Posts

  • #7, z sebastianMonday, 10. April 2017, 08:25 hodinky 8 years ago
    yeah, its a bit tricky to explain. Basically i wanted to overlay text with text (highlighted) to make it stand out. 
    The amount of if/else conditions to determine which text should be highlighted i have to do is terrible. The idea was to just make a "Display text" (lua) action which is also value sensitive inside the value string replacement tag:

    < vs=pagetext_< v=page > >

    in the end its too much work to get work properly :p I changed some colors so i dont need to overlay the text with text smile 

    Kapitán

    2346 Posts