Legacy GM Help with sounds

J

JDSTIGER

Guest
I keep getting this when the game launches

Code:
for object obj_sound:


global variable snd(100001, -2147483648) not set before reading it.
at gml_Object_obj_sound_CreateEvent_1 (line 2) - if (snd = 1)
I have a sprite for mute/unmute but it is not clickable..
Also I put a create sound when game launches into splash screen but it doesnt play it..
 
T

TDSrock

Guest
The problem here is that you have a value that is not set before trying to acces it.
The solution.
Before accesing do
Code:
variable = * insert value here *
 
J

JDSTIGER

Guest
The problem here is that you have a value that is not set before trying to acces it.
The solution.
Before accesing do
Code:
variable = * insert value here *
Fixed the sound but now how do I fix the Mute / Unmute sprites, it just glitches the image and wont mute it..
 
T

TDSrock

Guest
Show the relevant code. I won't know what wrong without seeing that ;)
 
D

Deleted member 3594

Guest
Code:
global.snd = 0;

if global.snd > 1 {global.snd = 0;}
if keyboard_check_pressed("your key") {global.snd += 1;}
if global.snd == 1 {your frame animation or instance create} //sound off
else {your frame animation or instance create} //sound on
 
J

JDSTIGER

Guest
Show the relevant code. I won't know what wrong without seeing that ;)
Code:
image_speed = 0
if (snd = 1)
{
image_index = 0
}
else
{
image_index = 1
}
Code:
global.snd = 0;

if global.snd > 1 {global.snd = 0;}
if keyboard_check_pressed("your key") {global.snd += 1;}
if global.snd == 1 {your frame animation or instance create} //sound off
else {your frame animation or instance create} //sound on
Thanks but what event is that
 
D

Deleted member 3594

Guest
It is used to move between the two frames of course. Create and step. Put (image_speed) in create event if you have not already done.
 
Last edited by a moderator:
T

TDSrock

Guest
Time to just dump the entire object to show me whats going on here.

Click the object. Press I or the "Show information" button.
 
J

JDSTIGER

Guest
Time to just dump the entire object to show me whats going on here.

Click the object. Press I or the "Show information" button.
Code:
Information about object: obj_sound
Sprite: spr_sound
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent:
Children:
Mask:

No Physics Object
Create Event:

execute code:

image_speed = 0
if (snd = 1)
{
image_index = 0
}
else
{
image_index = 1
}

Mouse Event for Left Button:

stop sound snd_main
 
T

TDSrock

Guest
Place a breakpoint in the code and run the game in debug mode. Based of this I can't see what is affecting the values.
What I suspect is that snd is changing each frame.
 
D

Deleted member 3594

Guest
Code:
Create event
snd = 0;
image_speed = 0;

Mouse event
snd += 1;
if snd > 1 {snd = 0;}

Step event
if snd == 1 {image_index = 1;}
else {image_index = 0;}

is simple.
 
J

JDSTIGER

Guest
Place a breakpoint in the code and run the game in debug mode. Based of this I can't see what is affecting the values.
What I suspect is that snd is changing each frame.
Forget my code, I just removed it, do you know one that will change the sprite and mute / unmute the sound
 
Top