Code Won't Work, Please Help

W

WillCampbell21

Guest
Basically, I am making a sound board app and I want it so that when you press on a button, it plays the sound and changes the instance. When I press the the button it plays the sound, changes the instance but it won't change back afterwards. Here is my code:

if (audio_is_playing(snd_druggo) == false)
{
audio_play_sound(snd_druggo, 1, 0);
}

if audio_is_playing(snd_druggo)
{
instance_change(obj_💩💩💩💩indruggo2, true);
}

else
{
instance_change(obj_💩💩💩💩indruggo, true);
}

Thanks guys!
Help.jpg
 

Xer0botXer0

Senpai
if (!audio_is_playing(snd_druggo) )
{
audio_play_sound(snd_druggo, 1, 0);
}

if audio_is_playing(snd_druggo)
{
instance_change(obj_****indruggo2, true);
}
else
{
instance_change(obj_****indruggo, true);
}

is instance_change a gms 2 function or did you write a script yourself ?

you could do
var inst = instance_create(x,y,obj_druggo);
inst.etc

where inst.etc is where you copy over relevant variable values to the new object.

I use 1.4 so you'll still need an answer to that function.
 
W

WillCampbell21

Guest
if (!audio_is_playing(snd_druggo) )
{
audio_play_sound(snd_druggo, 1, 0);
}

if audio_is_playing(snd_druggo)
{
instance_change(obj_****indruggo2, true);
}
else
{
instance_change(obj_****indruggo, true);
}

is instance_change a gms 2 function or did you write a script yourself ?

you could do
var inst = instance_create(x,y,obj_druggo);
inst.etc

where inst.etc is where you copy over relevant variable values to the new object.

I use 1.4 so you'll still need an answer to that function.


I'm also using 1.4 and instance_change is already a gm 1.4 function. Could you possibly give me an example of how I would use variables to do this piece of code. Usually I program on C++ and would normally work in this situation.

Thanks
 

Xer0botXer0

Senpai
My bad, I never saw that function! Learn something new everyday. :p

I haven't played around with sound functions, so if there's a problem with that part of your code I'm unsure. Which is why you should still wait for answers regarding that.

But hang on, let's look at this

If the specified audio is not playing, then play it.

If the specified audio is playing(it will now be playing) then change the calling instance to the specified new instance.. obj_****indruggo2
If the audio is not playing then change the calling instance to the specified obj_****indruggo

This code is all in the same step event, think about it, at the start of that code you check to see if the music is playing, if it isn't then play it and since it's playing change your instance to druggo2.. therefore the audio is always playing before that else enclosure will run. your
else
{
instance_change(obj_****indruggo, true);
}

Will never run.
 
Top