Difference between revisions of "RegisterEventHandler"

From The Official Visionaire Studio: Adventure Game Engine Wiki
Line 101: Line 101:
 
you should only include one instance of the "animationStarted" & "animationStopped" listener per game/project!
 
you should only include one instance of the "animationStarted" & "animationStopped" listener per game/project!
  
example: animationStarted & animationStopped
+
 
 +
Example: animationStarted & animationStopped
 
<syntaxhighlight>
 
<syntaxhighlight>
 
-- let's create the function which will perform the included functions or code provided; when an animation has been started!
 
-- let's create the function which will perform the included functions or code provided; when an animation has been started!
 
function onAnimStarted()
 
function onAnimStarted()
-- let's set a variable state to declare that an animation is playing!
 
var_state = 1
 
 
  print("an animation has been started!")
 
  print("an animation has been started!")
 
end
 
end
Line 112: Line 111:
 
-- let's create the function which will perform the included functions or code provided; when an animation has been stopped!
 
-- let's create the function which will perform the included functions or code provided; when an animation has been stopped!
 
function onAnimStopped()
 
function onAnimStopped()
-- let's set a variable state to declare that an animation has stopped playing!
+
  print("an animation has finished playing!")
var_state = 0
 
  print("an animation has been stopped!")
 
 
end
 
end
  
Line 126: Line 123:
  
 
<span class="medium bold underline">textStarted & textStopped</span>
 
<span class="medium bold underline">textStarted & textStopped</span>
 +
 +
 +
you should only include one instance of the "textStarted" & "textStopped" listener per game/project!
 +
 +
 +
Example: textStarted & textStopped
 +
<syntaxhighlight>
 +
-- let's create the function which performs the provided functions or code when text is being displayed!
 +
function onTextStarted()
 +
-- add a function to call or provide some code ...
 +
end
 +
 +
-- let's create the function which performs the provided functions or code when text has finished being displayed!
 +
function onTextStopped()
 +
-- add a function to call or provide some code ...
 +
end
 +
 +
-- let's create the event listeners to determine when a text is being displayed or has finished displaying!
 +
registerEventHandler("textStarted", "onTextStarted")
 +
registerEventHandler("textStopped", "onTextStopped")
 +
</syntaxhighlight>
  
  
Line 131: Line 149:
 
<span class="bold underline">Arguments</span>
 
<span class="bold underline">Arguments</span>
  
will add later!
+
<span class="bold">eventName</span>: "string" <br/>
 +
Current available events:
 +
* mainLoop: allows you to create a loop which executes functions & code provided inside of the "functionName"
 +
* mouseEvent: allows you to control what various mouse actions will do
 +
* animationStarted: allows you to execute functions & code provided inside of the "functionName" when an animation is started
 +
* animationStopped: allows you to execute functions & code provided inside of the "functionName" when an animation has ended
 +
* textStarted: allows you to execute functions & code provided inside of the "functionName" when text is being displayed
 +
* textStopped: allows you to execute functions & code provided inside of the "functionName" when text has finished being displayed
  
  

Revision as of 14:03, 3 April 2013

Command History

Available since v3.6
animationStarted, animationStopped, textStarted & textStopped event listener LUA commands added to v3.6
mouseEvent listener added to v3.7


registerEventHandler is an event listener which lets you declare what should happen when specific events are registered!

Additional Info

Current events available:
mainLoop, mouseEvent, animationStarted, animationStopped, textStarted & textStopped


Syntax:

registerEventHandler("eventName", "functionName", {integerValue or eventFlagName})


mainLoop

you should only include one instance of the "mainLoop" event per game/project!
currently there is no delay/pause method to control the speed of the loop!


Example 1: mainLoop (code inside of the loop event - not recommended!)

-- let's create the function for the mainLoop event!
function onMainLoop()
 -- if x equals less than 100 then + 1 should be added to value of x on each loop until x equals 100!
 if x < 100 then
  x = x + 1
 end
end

-- let's create the loop handler!
registerEventHandler("mainLoop", "onMainLoop")

Example 2: mainLoop (including functions inside of the loop event - recommended!)

-- let's create a function that we will include inside of the mainLoop event!
function checkValue()
 -- if x equals less than 100 then + 1 should be added to value of x on each loop until x equals 100!
 if x < 100 then
  x = x + 1
 end
end

 -- let's create the mainLoop event, where we will include functions for looping!
function onMainLoop()
 checkValue() -- calls checkVal function on each loop!
end

-- let's create the loop handler!
registerEventHandler("mainLoop", "onMainLoop")
end


mouseEvent

you should only include one instance of the "mouseEvent" listener per game/project!

Additional Info

Current mouseEvent eventFlags available: (if no mouseEvent flags are included then all mouse events will be registered!)
eEvtMouseMove(1), eEvtMouseLeftButtonDoubleClick(2), eEvtMouseLeftButtonDown(3), eEvtMouseLeftButtonUp(4), eEvtMouseLeftButtonHold(5), eEvtMouseLeftButtonHolding(6), eEvtMouseRightButtonDoubleClick(7), eEvtMouseRightButtonDown(8), eEvtMouseRightButtonUp(9), eEvtMouseMiddleButtonDown(10), eEvtMouseMiddleButtonUp(11), eEvtMouseWheelUp(12) & eEvtMouseWheelDown(13)


Example: mouseEvent

--[[
Like the mainLoop event you can create what each registered event should do inside of the mouseEvent function or you can add functions which could be called based on certain conditions or not!
--]]

-- let's create the function for the mouseEvent listener!
function onMouseEvent(eventType, mousePosition)
 -- bleh!
end

-- let's create the mouseEvent listener!
registerEventHandler("mouseEvent", "onMouseEvent", {eEvtMouseMove, eEvtMouseLeftButtonDoubleClick, eEvtMouseLeftButtonDown, eEvtMouseLeftButtonUp, eEvtMouseLeftButtonHold, eEvtMouseLeftButtonHolding, eEvtMouseRightButtonDoubleClick, eEvtMouseRightButtonDown, eEvtMouseRightButtonUp, eEvtMouseMiddleButtonDown, eEvtMouseMiddleButtonUp, eEvtMouseWheelUp, eEvtMouseWheelDown})

--[[
registerEventHandler("mouseEvent", "onMouseEvent", {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13})
would also work & saves time on having to type out all the string versions of the mouseEvents!
note: you don't need to add all of the mouseEvents; only add the ones you need for your game!
--]]


animationStarted & animationStopped

you should only include one instance of the "animationStarted" & "animationStopped" listener per game/project!


Example: animationStarted & animationStopped

-- let's create the function which will perform the included functions or code provided; when an animation has been started!
function onAnimStarted()
 print("an animation has been started!")
end

-- let's create the function which will perform the included functions or code provided; when an animation has been stopped!
function onAnimStopped()
 print("an animation has finished playing!")
end

-- let's create the event listener for checking when an animation has been started!
registerEventHandler("animationStarted", "onAnimStarted")

-- let's create the event listener for checking when an animation has finished!
registerEventHandler("animationStopped","onAnimStopped")


textStarted & textStopped


you should only include one instance of the "textStarted" & "textStopped" listener per game/project!


Example: textStarted & textStopped

-- let's create the function which performs the provided functions or code when text is being displayed!
function onTextStarted()
 -- add a function to call or provide some code ...
end

-- let's create the function which performs the provided functions or code when text has finished being displayed!
function onTextStopped()
 -- add a function to call or provide some code ...
end

-- let's create the event listeners to determine when a text is being displayed or has finished displaying!
registerEventHandler("textStarted", "onTextStarted")
registerEventHandler("textStopped", "onTextStopped")


Arguments

eventName: "string"
Current available events:

  • mainLoop: allows you to create a loop which executes functions & code provided inside of the "functionName"
  • mouseEvent: allows you to control what various mouse actions will do
  • animationStarted: allows you to execute functions & code provided inside of the "functionName" when an animation is started
  • animationStopped: allows you to execute functions & code provided inside of the "functionName" when an animation has ended
  • textStarted: allows you to execute functions & code provided inside of the "functionName" when text is being displayed
  • textStopped: allows you to execute functions & code provided inside of the "functionName" when text has finished being displayed


Flags

n/a (will add later)


Return

none