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/>
MovieVolume & GlobalVolume added to <span style="color:green">v3.8</span>
 
  
Allows the user to check current volume levels of: music, sound fx, speech, movies & global(master)
+
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
 
|-
 
|-
 
|
 
|
These are the numbers used inside of the getVolume(brackets) to check specific volume types! <br/>
+
Current events available: <br/>
  eMusicVolume (0), eSoundVolume (1), eSpeechVolume (2), eMovieVolume (3) or eGlobalVolume (4)
+
  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>
-- is music volume over 50%?
+
 
if getVolume(0) > 50 then
+
-- let's create the function for the mainLoop event!
  -- do some action!
+
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
  
-- is sound fx volume less than 25%?
+
-- let's create the loop handler!
if getVolume(1) < 25 then
+
registerEventHandler("mainLoop", "onMainLoop")
-- do some action!
+
</syntaxhighlight>
end
 
  
-- is speech volume more than or equal to 80%?
+
Example 2: mainLoop (including functions inside of the loop event - recommended!)
if getVolume(2) >= 80 then
+
<syntaxhighlight>
  -- do some action!
+
-- 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
  
-- is movie volume at 50%?
+
-- let's create the mainLoop event, where we will include functions for looping!
if getVolume(3) == 50 then
+
function onMainLoop()
  -- do some action!
+
  checkVal() -- calls checkVal function on each loop!
 
end
 
end
  
-- is global (master) volume not equal to 50%?
+
-- let's create the loop handler!
if getVolume(4) ~= 50 then
+
registerEventHandler("mainLoop", "onMainLoop")
-- do some action!
 
 
end
 
end
 
</syntaxhighlight>
 
</syntaxhighlight>
Line 46: Line 57:
  
 
<b><u>Arguments</u></b>
 
<b><u>Arguments</u></b>
 
type: integer <br/>
 
The type of volume to return: eMusicVolume (0), eSoundVolume (1), eSpeechVolume (2), eMovieVolume (3) or eGlobalVolume (4)
 
  
 
Flags: none
 
Flags: none
  
Return: volume <br/>
+
Return:<br/>
The queried volume
+
{{i18n|RegisterEventHandler}}
{{i18n|GetVolume}}
 

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: