Text in bubble or box

  • #30, z Simon_ASAWednesday, 28. September 2016, 12:34 hodinky 8 years ago
    Oh ok, thanks. Where does this "V" come from?
    Is it the V or S from the storage column on the data structure page?

    Despite using the correct syntax now, the line break still doesn't work. It still uses the 400 pixels defined in the font (in the font editor), and doesn't update to 190 pixels with the code:
    game:setValue(VFontLineWidth, 190)

    I guess this code has to be called before the text is displayed, which doesn't seem to be the case with my script. I'll try to find what's wrong this afternoon.

    Čestný člen

    321 Posts


  • #31, z afrlmeWednesday, 28. September 2016, 12:50 hodinky 8 years ago
    No, it's because it's not a game value. You have to link to a font not game.

    -- * function that listens out for text (display, narration) started * --
    function txtStart(text)
     local len = string.len(text.TextCurrentText)
     -- + --
     if len < 100 then
      Fonts[text.TextFont].FontLineWidth = 200
     elseif len > 100 and len < 200 then
      Fonts[text.TextFont].FontLineWidth = 300
     else
      Fonts[text.TextFont].FontLineWidth = 400
     end
    end
    
    registerEventHandler("textStarted", "txtStart") -- define event listener for handling text started
    

    According to the data structure, FontLineWidth is not scriptable, but that doesn't mean it won't update in-game (sometimes it requires reloading scene), but mostly it just means that the new value will not be stored in the save file data.

    As for V/S... V means the data is only stored in the ved launch / runtime. S means that the data will get stored in save files. I'm not sure why you have to add a V in front of data structure fields when using the old getObject method, I was told ages back that it's just a prefix thing.

    * edit: it doesn't seem to work correctly. What you could do is create 3 fonts with different line width values & then check the owner of the active font & the length to swap out the font. Not sure if it will work though.

    Imperátor

    7285 Posts

  • #32, z Simon_ASAWednesday, 28. September 2016, 14:51 hodinky 8 years ago
    You're right it's not working. I have created 3 fonts with different width. But again I don't understand what is the good syntax for the code roll
    I've tried:

    getObject("Characters[John]"):getLink(VCharacterFont("Fonts[Small_Font]"))
    


    "It's child's play to create a..." oh wait! It's difficult cry

    Čestný člen

    321 Posts

  • #33, z afrlmeWednesday, 28. September 2016, 15:00 hodinky 8 years ago
    If you are trying to update a value then it's setValue().

    Quick question: will all character fonts be the same color? If they are then it will make it much easier as you can just update the active texts font path.
    len = string.len(text.TextCurrentText)
    --print(text.TextOwner:getName(), len, text.TextCurrentText)
    
     if len < 50 then text.TextFont = Fonts["txt_default_(1)"]
     elseif len > 100 then text.TextFont = Fonts["txt_default_(3)"]
     else text.TextFont = Fonts["txt_default_(2)"] end
    

    That seems to be working for me, though there's a slight brief glitch the first time it swaps over to the new font.

    Imperátor

    7285 Posts

  • #34, z Simon_ASAWednesday, 28. September 2016, 15:11 hodinky 8 years ago
    It would probably be easier to show you the full script, as you may have suggestions:

    function setTextPosHook(text)
    
    local Bubble1 = getObject("Interfaces[Bubble_Large]")
    local Bubble2 = getObject("Interfaces[Bubble_Medium]")
    local Bubble3 = getObject("Interfaces[Bubble_Small]")
    local Character = getObject("Characters[Seb]")
    local Characterposition = Character:getPoint(VCharacterPosition)
    local CounterText = string.len(text.TextCurrentText)
    
    --[[
    Update Characterposition to prevent the bubbles and texts from going outside of the screen in 1280x720
    ]]--
    if Characterposition.x < 235 then Characterposition.x = 235 end
    if Characterposition.x > 1100 then Characterposition.x = 1100 end
    if Characterposition.y < 460 then Characterposition.y = 460 end
    
    
    if text:getLink(VTextOwner):getId().tableId == eCharacters and text:getLink(VTextOwner):getName() == "Seb" 
    then
     	 if CounterText<40 --if text as less than 40 characters, use small bubble interface.
     	 then
             [b]--Here I need to set the font with small width value--[/b]
      	 Bubble3:setValue(VInterfaceVisible, true)
     	 Bubble3:setValue(VInterfaceOffset,{x=Characterposition.x-40, y=Characterposition.y-380}) --position of small bubble
     	 setValue(VTextPosition, {x=Characterposition.x-18, y=Characterposition.y-350}) --position of text in bubble
    	 return true
     	 else
      		  if CounterText<100 --if text as less than 100 characters, use medium bubble interface.
       		  then
                      [b]--Here I need to set the font with medium width value--[/b]
        		  Bubble2:setValue(VInterfaceVisible, true)
        		  Bubble2:setValue(VInterfaceOffset,{x=Characterposition.x-185, y=Characterposition.y-440}) --position of medium bubble
        		  text:setValue(VTextPosition, {x=Characterposition.x-156, y=Characterposition.y-415}) --position of text in bubble
     		  return true
     		  else  --if text as more than 100 characters, use large bubble interface.
                               [b]--Here I need to set the font with large width value--[/b]
        			   Bubble1:setValue(VInterfaceVisible, true)
        			   Bubble1:setValue(VInterfaceOffset,{x=Characterposition.x-250, y=Characterposition.y-470}) --position of large bubble
        			   text:setValue(VTextPosition, {x=Characterposition.x-218, y=Characterposition.y-440}) --position of text in bubble
       			   return true
       		  end
     	end
    end
    end --function end
    
    function OnStopText(text) --hide interfaces
    getObject("Interfaces[Bubble_Large]"):setValue(VInterfaceVisible, false)
    getObject("Interfaces[Bubble_Medium]"):setValue(VInterfaceVisible, false)
    getObject("Interfaces[Bubble_Small]"):setValue(VInterfaceVisible, false)
    end
    
    registerHookFunction("setTextPosition", "setTextPosHook")
    registerEventHandler("textStopped","OnStopText")
    

    Čestný člen

    321 Posts

  • #35, z afrlmeWednesday, 28. September 2016, 16:36 hodinky 8 years ago
    Quick note: the txt position hook constantly loops whatever is in it unlike the text started & text stopped event handlers which only execute the code within one time per text started / stopped.

    P.S: not looked over all the script yet.

    Imperátor

    7285 Posts

  • #36, z Simon_ASAWednesday, 28. September 2016, 19:26 hodinky 8 years ago
    Thanks for the note.
    But it's useless, when I manage to solve something, I discover another problem... roll I think I'll give up with the bubbles and will just use the default VS texts.

    Even if I can solve the text width to fit in the bubbles, I will have this other problem: the bubbles and texts are displayed for one specific character, but I would like to have them for all characters. I will have many characters who will talk, so it will be difficult to create a different script for each of them...

    Čestný člen

    321 Posts

  • #37, z afrlmeWednesday, 28. September 2016, 20:19 hodinky 8 years ago
    You don't necessarily have to create a script for them, maybe just a table that you could add speech bubble offset values into for each character that will talk, then you can check the text owners name & access the offset values in the table.

    Say the offset values are based on 100% character scale, so you take those values & calculate the offset value against the characters current scale value to get the actual offset to make sure it's the same amount of distance above the head regardless of the current size of the character doing the talking.

    Optionally I guess you could consider doing something similar to the Broken Sword remastered / director's cut editions where they had a speech bubble looking thing, like so...

    http://www.touchmyapps.com/wp-content/uploads/2010/05/ar-broken-sword-directors-cut-hd-6.jpg

    If it's fixed position then it would be easier for you to sort out which speech bubble you need to use or you could even create each text as a image / animation. There's lots of different approaches you could use. Statically positioned text is definitely easier though.

    Imperátor

    7285 Posts