Global Command: registerHookFunction

From The Official Visionaire Studio: Adventure Game Engine Wiki
Revision as of 09:20, 22 May 2023 by EK (talk | contribs)

Register a hook function for a specific operation.


Syntax

registerHookFunction(operation, hookFunction)


Parameters

Parameter Type Supported values Description
operation string "getActionText" Hook into the action text display. Lets you change/set the action text. The operation for which the hook function should be called.
"getCharacterAnimationIndex" Hook into the change of the character animation. Lets you change/set the character animation index.
"setTextPosition" Hook into the text display. Lets you change/set the text position.
"textRender" Hook into the text display. Lets you write your own rendering routine.
"textText" Hook into the text display. Lets you change/set the current text.
hookFunction string The name of the function which is called when the hook is executed. See the table below for the arguments the function takes.


Hook function

Depending on the operation, the hook function takes and returns different arguments/values.

operation Arguments Description Return value
"getActionText" mousePos (t_point) The current mouse position (an associative array containing the elements x (int) and y (int)). The new action text (str).
actionText (str) The default action text generated by the engine.
"getCharacterAnimationIndex" character (TVisObj) The current character object. Index (0-based) of the character animation to use for the new direction (int).

If -1 is returned, the index is handled by the engine, ignoring the hook.

animState (int) The current animation state. Supported values:
  • eNoAnim (0)
  • eWalkAnim (1)
  • eTalkAnim (2)
  • eStandingAnim (3)
  • eCharacterAnim (4)
  • eRandomAnim (5)
newDirection (int) The direction of the upcoming character animation.
"setTextPosition" text (TVisObj) The affected text object. True if the operation was handled in the hook function, false if the operation should be handled by the engine, ignoring the hook (bool).
"textRender" text (TVisObj) The affected text object. True if the rendering was handled in the hook function, false if the engine should render the text, ignoring the hook (bool).
"textText" text (TVisObj) The affected text object. The text to display (str).


Return values

none


Examples

Example 1: Generate an individual action text.

function myActionText(mousePos, actionText)
  local obj = game.CurrentObject
  
  if obj:getId().tableId == eObjects then
    return 'This is a ' .. obj:getTextStr(VObjectName)
  else
  	return ""
  end
end

registerHookFunction("getActionText", "myActionText")


Example 2: Place character texts in the top left corner of the screen (assuming text alignment is set to "Left" in the game properties).

function myTextPosition(text)
  local owner = text.Owner

  if owner:getId().tableId == eCharacters then
    text.Position = {x = game.ScrollPosition.x + 30, y = game.ScrollPosition.y + 30}

    return true
  else
    return false
  end
end

registerHookFunction("setTextPosition", "myTextPosition")