A question about display text reposition

  • #1, by UraalMonday, 28. October 2013, 21:32 11 years ago
    So I've returned to wonderful world of (attempted) scripting now that I'm taking some coding classes (maybe I have better chance of actually understanding this all).

    Tho there's something essential I must be missing with this code:

    -- let's create the function which sets the position of displayed text
    function setTextPosHook(text)
     -- if text owner is a character then...
     if text:getLink(VTextOwner):getId().tableId == eCharacters then
      text:setValue(VTextPosition, {x=960, y=100})
     end
    end
    
    -- let's create the event listener for handling position of displayed text
    registerHookFunction("setTextPosition", "setTextPosHook")
    


    That's pretty much a copy pasted script file from wiki that I have put into my project's execution script library. Now I don't know how this is activated by I tried to:

    1. Call script
    2. Display text (of current character)

    Text of the character didn't change the position but is instead (and still) displayed on top of the character, I must be doing something awfully wrong here smile (probly something laughably simple I have completely misunderstood) .

    Do I need to use some command inside the Display text to run this script or what em I doing wrong? smile

    Newbie

    93 Posts


  • #2, by AlexMonday, 28. October 2013, 22:31 11 years ago
    Your script should be set to 'definition script' so it gets executed automatically when the game starts. If you have trouble with a script you should make print calls to find out what's wrong.

    btw, you should rename the thread title to a useful title. Almost all threads contain a question...

    Great Poster

    378 Posts

  • #3, by UraalMonday, 28. October 2013, 23:12 11 years ago
    Ah yes that whole code is now definition script. How/where can I define when character text is displayed according to this definition script?

    Thanks in advance!

    (Ah oopsies, accidental topic smile, corrected now)

    Newbie

    93 Posts

  • #4, by afrlmeTuesday, 29. October 2013, 00:51 11 years ago
    with this script in question being a hook, & in particular an event listener - meaning it listens out for each time text is displayed - you would have to create multiple if queries to determine where to place text for x character for x scene.

    -- example 1: if character is "some character name" ...
    
    -- let's create the function which sets the position of displayed text
    function setTextPosHook(text)
     -- if text owner is a character then...
     if text:getLink(VTextOwner):getId().tableId == eCharacters then
      if text:getLink(VTextOwner):getName() == "add character name here" then
       text:setValue(VTextPosition, {x=960, y=100})
      end
      -- etc ...
     end
    end
    
    -- let's create the event listener for handling position of displayed text
    registerHookFunction("setTextPosition", "setTextPosHook")
    


    -- example 2: if character is "some character name" & scene is "some scene" ...
    
    -- let's create the function which sets the position of displayed text
    function setTextPosHook(text)
     -- if text owner is a character then...
     if text:getLink(VTextOwner):getId().tableId == eCharacters then
      if text:getLink(VTextOwner):getName() == "add character name here" and game:getLink(VGameCurrentScene):getName() == "add scene name here" then
       text:setValue(VTextPosition, {x=960, y=100})
      end
      -- etc ...
     end
    end
    
    -- let's create the event listener for handling position of displayed text
    registerHookFunction("setTextPosition", "setTextPosHook")
    


    you could create multiple variations on where, how & when to display text in a new position via the use of multiple if queries such as the 2 methods I've shown examples for above or by querying whether or not a certain condition is true/false or whether or not a value equals a certain integer value or even combine the various queries together & so on.

    Imperator

    7278 Posts

  • #5, by UraalTuesday, 29. October 2013, 09:14 11 years ago
    So I gave scene a name "emohall" (at scene -> properties -> scenename) and also named character I want my script to affect the name "emo". Then I placed following code as a definition script:

    -- example 2: if character is "some character name" & scene is "some scene" ...
    
    -- let's create the function which sets the position of displayed text
    function setTextPosHook(text)
     -- if text owner is a character then...
     if text:getLink(VTextOwner):getId().tableId == eCharacters then
      if text:getLink(VTextOwner):getName() == "emo" and game:getLink(VGameCurrentScene):getName() == "emohall" then
       text:setValue(VTextPosition, {x=9, y=1})
      end
      -- etc ...
     end
    end
    
    -- let's create the event listener for handling position of displayed text
    registerHookFunction("setTextPosition", "setTextPosHook")
    


    Unfortunately script does nothing when character "emo" starts talking in the room "emohall". The language I use for names is "Unnamed" <- default and my Visionaire editor version is 3.7.1 (Build 1149). I tried to take those "" away around the names (emo && emohall) yet it didn't work either. Some of the things character says is made with Display text and some are within the conversation tree, yet neither changes. Is there something fundamental I have misunderstood?

    Newbie

    93 Posts

  • #6, by afrlmeTuesday, 29. October 2013, 16:15 11 years ago
    && is not allowed in Lua...

    it is used in php, various c programming languages & a few others but in Lua you have to use "and"

    if
    else
    elseif
    and
    or
    end
    not
    
    etc....
    


    The game language names have to be written in English (I think, Alex or David can confirm this, or correct me)

    the name is not taken from the names you type/add via the fields where you can add names for different languages, but is taken from the object name itself... (see attachments)

    Check out this link @ http://wiki.visionaire-tracker.net/wiki/Basic_lua -for a quick guide to basic lua operators, conditions & other stuff, I have been typing up. Everything includes an example or two wink

    Imperator

    7278 Posts

  • #7, by UraalThursday, 30. January 2014, 22:48 11 years ago
    Hmm maybe I have fundamentally misunderstood something, but the following script:

    function OnStartText(text)
    text:setValue(VTextPosition, {x=9, y=1})
    end
    
    --function OnStopText(text)
    --end
    
    --function OnMainLoop()
    --end
    
    registerEventHandler("textStarted","OnStartText")
    --registerEventHandler("textStopped","OnStopText")
    --registerEventHandler("mainLoop", "OnMainLoop")
    
    
    


    Still makes the text appear completely middle of the character:

    https://dl.dropboxusercontent.com/u/20899096/wrongtextposi.png

    Newbie

    93 Posts

  • #8, by afrlmeFriday, 31. January 2014, 01:01 11 years ago
    use the hook function instead for character related text...
    function setTextPosHook(text)
     text:setValue(VTextPosition, {x=9, y=1})
    end
    
    registerHookFunction("setTextPosition", "setTextPosHook")
    

    & remember - you can only have one of each event listener/handler/hook per game project.

    Imperator

    7278 Posts

  • #9, by UraalSaturday, 22. March 2014, 13:27 10 years ago
    Okay, finally cracked it. Thanks for the help! smile

    This code goes to "scripts" as an definition script (from properties). It basically runs on background waiting for event when a character "name" (name being any characters name you want to be affected by the script, name is taken from list of characters inside the visionaire editor) launches and then displays that text in given position (x and y).

    function setTextPosHook(text)
     if text:getLink(VTextOwner):getId().tableId == eCharacters and text:getLink(VTextOwner):getName() == "name" then
      text:setValue(VTextPosition, {x=750, y=330})
      return true
     end
    end
    
    registerHookFunction("setTextPosition", "setTextPosHook")
    

    Newbie

    93 Posts

  • #10, by afrlmeSaturday, 22. March 2014, 15:59 10 years ago
    yeah smile

    I forgot to include the return true part to the example I gave you... d'oh!

    Imperator

    7278 Posts

  • #11, by andiliddellTuesday, 08. July 2014, 01:38 10 years ago
    can you unregister this hook function once you're done using it?

    I have some character custom animations with a different registration point and size so the text is out of position for a small time, which i would like to fix with this, but then stop listening for the hook once im done, and go back to the default above the head position.

    It would be a really great addition (and pretty simple i imagine) if they could add a "define text position" dialog for display text by character when you don't want the default over head position?

    Forum Fan

    178 Posts