Difference between revisions of "GetSoundId"

From The Official Visionaire Studio: Adventure Game Engine Wiki
(Created page with "<div class="toccolours mw-collapsible mw-collapsed" style="background: #f0f0f0; border: 1px dashed darkgrey" width="100%"> <b>Command History</b> <div class="mw-collapsible-co...")
 
Line 6: Line 6:
  
  
Allows you to play sound files; with optional property values!
+
Use this to store the sound.id for an audio file into a variable, which you can use for stopping/pausing said sound or editing the sounds properties!
<div class="toccolours mw-collapsible mw-collapsed" style="background: #f0f0f0; border: 1px dashed darkgrey" width="100%">
+
 
<b>Additional Info</b>
 
<div class="mw-collapsible-content">
 
<div>Properties currently available:
 
<pre>volume, balance, offset & loop</pre>
 
Please note that only mono sounds can be panned using the balance property; all stereo channel sounds will be centered!</div>
 
</div></div>
 
  
  
 
Syntax:
 
Syntax:
 
<syntaxhighlight>
 
<syntaxhighlight>
startSound("filename", {flags=1, properties})
+
getSoundId("filename")
 
</syntaxhighlight>
 
</syntaxhighlight>
  
  
Example 1: basic play audio file method!
 
<syntaxhighlight>
 
startSound("sounds/example.ogg")
 
</syntaxhighlight>
 
 
Example 2: again with properties!
 
 
<syntaxhighlight>
 
<syntaxhighlight>
-- play example.ogg at 100% volume level, audio centered, from 1 second mark with loop mode on!
+
-- let's store the sound ID into a variable for later use!
startSound("sounds/example.ogg", {flags=1, volume=100, balance=0, offset=1000 loop=true})
+
local soundID = getSoundId("sounds/example.ogg")
 
 
--[[
 
let's say you have an audio file with a duration of 00:03:24 & you want to start the audio file at: 2 minutes & 44 seconds;
 
so what we need to do is convert minutes/seconds into ms like so: (2*60)*1000 + (44*1000) = 164000ms
 
 
 
math explanation:
 
2m*60s = 120 seconds * 1000ms = 120,000ms | 44s*1000ms = 44,000ms
 
120,000 + 44,000 = 164,000ms
 
--]]
 
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Line 47: Line 26:
  
 
<b>filename</b>: path <br/>
 
<b>filename</b>: path <br/>
The path to the audio file to be played! ("path/filename.type")
+
The path to the audio file whose ID we want to obtain! ("path/filename.type")
  
  
 
<b><u>Flags</u></b>
 
<b><u>Flags</u></b>
  
<b>properties</b>
+
none
* volume: allows you to set volume level via an integer value
 
* balance: allows you to set the left/right audio balance via an integer value (-1000/0/1000)
 
* offset: allows you to start audio file from x time via an integer value (in ms)
 
* loop: allows you to declare if audio file should loop via a boolean value (true/false)
 
  
  
 
<b><u>Return</u></b>
 
<b><u>Return</u></b>
  
none
+
<b>id</b> <br/>
{{i18n|StartSound}} <br/>
+
Returns the sound ID as an integer value.
 +
{{i18n|GetSoundId}} <br/>
 
{| style="background: #f0f0f0; border: 1px dashed darkgrey" width="100%"
 
{| style="background: #f0f0f0; border: 1px dashed darkgrey" width="100%"
 
|-
 
|-
 
|<b>Relevant Pages</b>: [[GetSoundProperty|getSoundProperty]] - [[SetSoundProperty|setSoundProperty]] - [[StartSound|startSound]] - [[StopSound|stopSound]] - [[ToggleSoundPause|toggleSoundPause]]
 
|<b>Relevant Pages</b>: [[GetSoundProperty|getSoundProperty]] - [[SetSoundProperty|setSoundProperty]] - [[StartSound|startSound]] - [[StopSound|stopSound]] - [[ToggleSoundPause|toggleSoundPause]]
 
|}
 
|}

Revision as of 22:36, 13 March 2013

Command History

Available since v3.8


Use this to store the sound.id for an audio file into a variable, which you can use for stopping/pausing said sound or editing the sounds properties!


Syntax:

getSoundId("filename")


-- let's store the sound ID into a variable for later use!
local soundID = getSoundId("sounds/example.ogg")


Arguments

filename: path
The path to the audio file whose ID we want to obtain! ("path/filename.type")


Flags

none


Return

id
Returns the sound ID as an integer value.


Relevant Pages: getSoundProperty - setSoundProperty - startSound - stopSound - toggleSoundPause