Difference between revisions of "RegisterEventHandler"
From The Official Visionaire Studio: Adventure Game Engine Wiki
Line 1: | Line 1: | ||
<b>History</b>: Available since <span style="color:green">v3.7</span> <br/> | <b>History</b>: Available since <span style="color:green">v3.7</span> <br/> | ||
− | |||
− | + | registerEventHandler is an event listener which lets you declare what should happen when specific events are registered! | |
{| class="mw-collapsible mw-collapsed" style="background: #f0f0f0; border: 1px dashed darkgrey" width="100%" | {| class="mw-collapsible mw-collapsed" style="background: #f0f0f0; border: 1px dashed darkgrey" width="100%" | ||
! Additional Info | ! Additional Info | ||
|- | |- | ||
| | | | ||
− | + | Current events available: <br/> | |
− | + | mainLoop, mouseEvent, animationStarted, animationStopped, textStarted & textStopped | |
|} | |} | ||
Line 16: | Line 15: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | Example: | + | <span style="font-size:12px"><b><u>mainLoop</u></b></span> |
+ | |||
+ | you should only include one instance of the "mainLoop" event per game/project! <br/> | ||
+ | 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!) | ||
<syntaxhighlight> | <syntaxhighlight> | ||
− | -- | + | |
− | + | -- 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 | end | ||
− | -- | + | -- let's create the loop handler! |
− | + | registerEventHandler("mainLoop", "onMainLoop") | |
− | + | </syntaxhighlight> | |
− | |||
− | -- | + | Example 2: mainLoop (including functions inside of the loop event - recommended!) |
− | + | <syntaxhighlight> | |
− | -- | + | -- 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 | end | ||
− | -- | + | -- let's create the mainLoop event, where we will include functions for looping! |
− | + | function onMainLoop() | |
− | -- | + | checkVal() -- calls checkVal function on each loop! |
end | end | ||
− | -- | + | -- let's create the loop handler! |
− | + | registerEventHandler("mainLoop", "onMainLoop") | |
− | |||
end | end | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Line 46: | Line 57: | ||
<b><u>Arguments</u></b> | <b><u>Arguments</u></b> | ||
− | |||
− | |||
− | |||
Flags: none | Flags: none | ||
− | Return: | + | Return:<br/> |
− | + | {{i18n|RegisterEventHandler}} | |
− | {{i18n| |
Revision as of 19:27, 5 March 2013
History: Available since 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()
checkVal() -- calls checkVal function on each loop!
end
-- let's create the loop handler!
registerEventHandler("mainLoop", "onMainLoop")
end
Arguments
Flags: none
Return: