|
| 1 | +# steamworks.addEventListener() |
| 2 | + |
| 3 | +> --------------------- ------------------------------------------------------------------------------------------ |
| 4 | +> __Type__ [Function][api.type.Function] |
| 5 | +> __Return value__ [Boolean][api.type.Boolean] |
| 6 | +> __Revision__ [REVISION_LABEL](REVISION_URL) |
| 7 | +> __Keywords__ steam, steamworks, event, addEventListener |
| 8 | +> __See also__ [steamworks.removeEventListener()][plugin.steamworks.removeEventListener] |
| 9 | +> [steamworks.*][plugin.steamworks] |
| 10 | +> --------------------- ------------------------------------------------------------------------------------------ |
| 11 | +
|
| 12 | + |
| 13 | +## Overview |
| 14 | + |
| 15 | +Adds a listener to the plugin's collection of event listeners. When the named event occurs, the listener will be invoked and be supplied with a table representing that event. |
| 16 | + |
| 17 | +Returns `true` if the listener was successfully added to the plugin. Returns `false` if given invalid arguments, such as the listener not being a function or if it's a table that is missing a function matching the event name. |
| 18 | + |
| 19 | + |
| 20 | +## Syntax |
| 21 | + |
| 22 | + steamworks.addEventListener( eventName, listener ) |
| 23 | + |
| 24 | +##### eventName ~^(required)^~ |
| 25 | +_[String][api.type.String]._ The name of the event to listen for. Must be one of the following: |
| 26 | + |
| 27 | +* `"achievementImageUpdate"` ([reference][plugin.steamworks.event.achievementImageUpdate]) |
| 28 | +* `"achievementInfoUpdate"` ([reference][plugin.steamworks.event.achievementInfoUpdate]) |
| 29 | +* `"microtransactionAuthorization"` ([reference][plugin.steamworks.event.microtransactionAuthorization]) |
| 30 | +* `"overlayStatus"` ([reference][plugin.steamworks.event.overlayStatus]) |
| 31 | +* `"userInfoUpdate"` ([reference][plugin.steamworks.event.userInfoUpdate]) |
| 32 | +* `"userProgressSave"` ([reference][plugin.steamworks.event.userProgressSave]) |
| 33 | +* `"userProgressUnload"` ([reference][plugin.steamworks.event.userProgressUnload]) |
| 34 | +* `"userProgressUpdate"` ([reference][plugin.steamworks.event.userProgressUpdate]) |
| 35 | + |
| 36 | +##### listener ~^(required)^~ |
| 37 | +_[Listener][api.type.Listener]._ The listener to be invoked when the plugin dispatches an event whose `name` property matches the given `eventName` argument. This argument must be a function or a table object containing a function having the same name as the event. |
| 38 | + |
| 39 | + |
| 40 | +## Example |
| 41 | + |
| 42 | +``````lua |
| 43 | +local steamworks = require( "plugin.steamworks" ) |
| 44 | + |
| 45 | +-- Set up a listener to be called when Steam's overlay has been shown/hidden |
| 46 | +local function onSteamOverlayStatusChanged( event ) |
| 47 | + print( "Steam overlay phase: " .. event.phase ) |
| 48 | +end |
| 49 | +steamworks.addEventListener( "overlayStatus", onSteamOverlayStatusChanged ) |
| 50 | + |
| 51 | +-- Set up a listener to be called when a Steam user's info has been changed |
| 52 | +local function onSteamUserInfoUpdated( event ) |
| 53 | + print( "Steam user info has changed." ) |
| 54 | +end |
| 55 | +steamworks.addEventListener( "userInfoUpdate", onSteamUserInfoUpdated ) |
| 56 | +`````` |
0 commit comments