Game Maker - Turn On/Off Sound
<p><strong>What I have</strong></p>
<p>I have two rooms: <code>rm_home</code> and <code>rm_options</code>. I have a sound: <code>snd_Bgm</code>. And, I have three objects: <code>obj_bgm</code>, <code>obj_BtnOnClicked</code>, and <code>obj_BtnOffClicked</code>.</p>
<p><strong>What I want is very simple</strong></p>
<p>Player can turn on/off the <code>snd_Bgm</code>.</p>
<p><strong>What I have done</strong></p>
<p>In <code>obj_bgm</code>, I have these events:</p>
<blockquote>
<p>Create Event: set var <code>global.sound to 1</code></p>
<p>Room Start: stop sound <code>snd_Bgm</code>; if <code>global.sound == 1</code> then play sound <code>snd_Bgm</code></p>
</blockquote>
<p>In <code>obj_BtnOnClicked</code>, I have these events:</p>
<blockquote>
<p>Left-Pressed Event: play sound <code>snd_Bgm</code>; set var <code>global.sound to 1</code></p>
</blockquote>
<p>In <code>obj_BtnOffClicked</code>, I have these events:</p>
<blockquote>
<p>Left-Pressed Event: stop sound <code>snd_Bgm</code>; set var <code>global.sound to 0</code></p>
</blockquote>
<p>I put <code>obj_BtnOnClicked</code>, and <code>obj_BtnOffClicked</code> in <code>rm_options</code>, which can be accessed from <code>rm_home</code>. Then, I put <code>obj_bgm</code> in <code>rm_home</code>.</p>
<p><strong>This is the problem</strong></p>
<p>When game start, it will show <code>rm_home</code> and plays the <code>snd_bgm</code>. I go to <code>rm_options</code>, then click the <code>obj_BtnOffClicked</code> to turn off the sound, so the sound is off. But, when I go back to <code>rm_home</code>, the sound is on again.</p>
<p><strong>What I think</strong></p>
<p>I shouldn't put <code>Create Event: set var global.sound to 1</code> in <code>obj_bgm</code>, because when <code>rm_home</code> start, it takes the value of var <code>global.sound</code> from <em>Create Event</em>. But, if I put <em>Create Event</em> in <code>obj_BtnOnClicked</code> or <code>obj_BtnOffClicked</code>, it shows a <em>Get Error</em>.</p>
<p>What should I do? Please explain your answer. Thanks.</p>