How do i unregister a hook function

  • #1, by andiliddellSunday, 16. February 2014, 01:04 10 years ago
    I've seen the documentation about unregistering an event listener but how do i cancel a hook function?

    I have a hook function to reposition text in a particular room when a certain condition is true.

    Once these conditions are false, the text doesn't go back to the usual place? so i want to unhook the function.

    Im assuming the hooked version overrides the default positioning of the text over the characters head

    Forum Fan

    178 Posts


  • #2, by afrlmeSunday, 16. February 2014, 02:43 10 years ago
    the unregister thing is new to the upcoming release. I'm not sure it covers the hook function?

    the code you added in the hook is processed each time a spoken text is called... but you could make it so it only works if a condition or value is met instead.

    ok let's say you have a condition called "hook_active" - you would set this to true to allow the code inside of the function to be processed & false to ignore the code in the function.

    function setTextPosHook(text)
    if getObject("Conditions[hook_active]"):getBool(VConditionValue) then
     if text:getLink(VTextOwner):getId().tableId == eCharacters then
      if text:getLink(VTextOwner):getName() == "chicken" and game:getLink(VGameCurrentScene):getName() == "03_inside hut" then
        text:setValue(VTextPosition, {x= game:getPoint(VGameWindowResolution).x/2, y=500})
       end
      end
     end
    return true
    end
    
    registerHookFunction("setTextPosition", "setTextPosHook")
    

    Imperator

    7278 Posts

  • #3, by andiliddellSunday, 16. February 2014, 12:29 10 years ago
    thanks again. Just one thing that stands out to me here in my knowledge gap of the data structure..

    When you use getObject on the Conditions table, how do you know which conditions table this is?

    The conditions tab within the active interface?, or the conditions specified on an object?.

    This has puzzled me alot whilst trying to learn this? How do you target specific conditions on objects etc?

    And what is getLink actually doing (in laymans terms), and how does it differ from getLinkS?

    Sorry to ask such dumb fundamentals on this thread but i cant seem to find a decent explanation anywhere else?

    Forum Fan

    178 Posts

  • #4, by andiliddellSunday, 16. February 2014, 12:39 10 years ago
    I suppose the simplest example that puzzles me is this:

    verbstring = getObject("Values[verb]"):getStr(VValueString)
    


    I assumed this would get me the STRING value from the VERB value specified on the current objects VALUES tab... but it doesnt?

    How would i specify i want to get the item currently under the cursors VERB STRING VALUE:
    the data wiki says under cursor item = game:getLink(VGameCurrentObject) but what type of dtat does this return? and how do i fish out its value table and change the verb entry to a string?

    Im confused razz

    Forum Fan

    178 Posts

  • #5, by AlexSunday, 16. February 2014, 12:56 10 years ago
    your example looks correct to me. First I'd verify the getObject call. Maybe you have multiple values with the same name?

    the type of VGameCurrentObject depends on the object itself. You have to test the type, e.g.:
    var obj = game:getLink(VGameCurrentObject) 
    if obj:getId().tableId == eCharacters then
    ...
    elseif obj:getId().tableId == eObjects then
    ...
    end
    


    and so on

    Great Poster

    378 Posts

  • #6, by andiliddellSunday, 16. February 2014, 13:10 10 years ago
    Hey alex

    I do have multiple values with the same name. Im trying to specify a verb string for each scene object using the string value in the editor.

    Im so used to AS3 dot notation i'd expect something like ActiveObject.values.verb but appreciate this object model doesn't work like that, and ll objects of the same type are in one table.

    One other issue is that when i hold down the mouse button over a scene object to get the verb coin interface to popup, and then move over the action button, that becomes the active object and it seems i lose access to the scene object i was hovering over.

    Think it might be time to ditch my coin ui... its becoming a real pain to get action text to work with it

    Forum Fan

    178 Posts

  • #7, by afrlmeSunday, 16. February 2014, 13:52 10 years ago

    When you use getObject on the Conditions table, how do you know which conditions table this is?

    The conditions tab within the active interface?, or the conditions specified on an object?.

    This has puzzled me alot whilst trying to learn this? How do you target specific conditions on objects etc?

    getObject("Conditions[condition_name]")
    

    is a global get conditions as it targets all conditions inside of the conditions table. you need to make sure that you don't have multiple conditions with the same name in your project if you plan on using Lua to retrieve conditions.

    The safe method for getting objects, conditions & values in general is to directly link to them.
    -- example 1: condition linked to a scene
    getObject("Scenes[scene_name].SceneConditions[condition_name]")
    
    -- example 2: condition linked to a scene object
    getObject("Scenes[scene_name].SceneObjects[object_name].ObjectConditions[condition_name]")
    


    And what is getLink actually doing (in laymans terms), and how does it differ from getLinks?

    getLink returns one specific object from the data structure...
    -- return current object underneath the mouse cursor...
    game:getLink(VGameCurrentObject)
    

    whereas getLinks returns all data associated with the initial objects table based on which getLinks table you just queried.
    -- gets all texts associated with the current game object...
    texts = game:getLink(VGameCurrentObject):getLinks(VTextAll)
    entry1 = texts[1]:getStr(VTextLanguageText) -- gets text from first table entry
    


    Sorry to ask such dumb fundamentals on this thread but i cant seem to find a decent explanation anywhere else?

    They are some good questions! wink have I not added any of this data to the wiki anywhere yet? I thought I added some examples/explanations in regards to the different getObject methods a while back, but I could have just posted them in a thread on this forum somewhere - bad memory.

    Imperator

    7278 Posts

  • #8, by andiliddellSunday, 16. February 2014, 14:53 10 years ago
    Thanks for the explanations, that seems much clearer! smile

    How do you know which id of the data array certain things are in?

    texts[1] ... For example, is this because there is only 1 table entry or for a gamecurrentObject? or is there a definition somewhere for how many entries and what order they are in for each object type?

    Or am I digging a deeper hole here razz

    Forum Fan

    178 Posts

  • #9, by AlexSunday, 16. February 2014, 15:06 10 years ago
    depending on the field type you need to call getLink (returns exactly one object - which could be empty) or getLinks (returns 0 to n object entries).
    http://wiki.visionaire-tracker.net/wiki/Data_Structure

    in case of texts the number of entries depends on the number of languages you have created for your game. If you have more than 1 language you need to iterate all texts and find the one for the current language.

    Great Poster

    378 Posts

  • #10, by afrlmeSunday, 16. February 2014, 16:00 10 years ago
    the number I added in the square brackets was index 1 - meaning I returned the data from the first data entry. you can get the exact number of entries in a table in various ways but the simplest method is to use table.maxn()...
    -- return total amount of entries in x table...
    print(table.maxn(table_name))
    

    what Alex mentioned about iterating would be done by querying each data entry to return one that matches what you needed.
    -- for i = 1 to table entry total value do....
    for i = 1, table.maxn(t) do
     if texts[i]:getLink(VTextLanguageLanguage) == game:getLink(VGameStandardLanguage):getName() then
      texts:setValue(VTextLanguageText, "some new text here..."); break
     end
    end
    

    here's a nice website/blog I found a wee bit ago, for learning Lua: http://www.phailed.me/2011/02/learn-lua-the-hard-way-tables/ it's easy enough to understand, has screenshots & exercises etc for you to try out.

    Imperator

    7278 Posts

  • #11, by andiliddellSunday, 16. February 2014, 21:30 10 years ago
    Thanks for the info Very helpful indeed.

    Back on the original topic of hookfunctions, even once the hook-active condition is false, does the hook function still override the default text position function?

    Its just once that condition is changed to false, it starts lining the text up at 0,0 in the top left of the screen as if the hook function means the default behaviour is never ran?

    Forum Fan

    178 Posts