1
\$\begingroup\$

What I have

I have two rooms: rm_home and rm_options. I have a sound: snd_Bgm. And, I have three objects: obj_bgm, obj_BtnOnClicked, and obj_BtnOffClicked.

What I want is very simple

Player can turn on/off the snd_Bgm.

What I have done

In obj_bgm, I have these events:

Create Event: set var global.sound to 1

Room Start: stop sound snd_Bgm; if global.sound == 1 then play sound snd_Bgm

In obj_BtnOnClicked, I have these events:

Left-Pressed Event: play sound snd_Bgm; set var global.sound to 1

In obj_BtnOffClicked, I have these events:

Left-Pressed Event: stop sound snd_Bgm; set var global.sound to 0

I put obj_BtnOnClicked, and obj_BtnOffClicked in rm_options, which can be accessed from rm_home. Then, I put obj_bgm in rm_home.

This is the problem

When game start, it will show rm_home and plays the snd_bgm. I go to rm_options, then click the obj_BtnOffClicked to turn off the sound, so the sound is off. But, when I go back to rm_home, the sound is on again.

What I think

I shouldn't put Create Event: set var global.sound to 1 in obj_bgm, because when rm_home start, it takes the value of var global.sound from Create Event. But, if I put Create Event in obj_BtnOnClicked or obj_BtnOffClicked, it shows a Get Error.

What should I do? Please explain your answer. Thanks.

\$\endgroup\$
1
\$\begingroup\$

I do believe that each time you enter a room, you create a new instance of obj_bgm, unless it is a persistent object. So, you are constantly setting global.sound to be 1 when you enter the room.

If it is not a persistent object, change it to be one, and it should fix the problem. (This should be as simple as checking the box that says "persistent" to the right of the the events window.)

\$\endgroup\$
2
  • \$\begingroup\$ It works! I don't know about persistent object before. Thanks \$\endgroup\$ – Grace Michelle Jun 15 '16 at 6:22
  • \$\begingroup\$ Not a problem. We all start somewhere. \$\endgroup\$ – SangoProductions Jun 15 '16 at 7:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.