Game Maker Community YoYo Games

Welcome Guest ( Log In | Register )

> Novice Forum Rules

Novice and intermediate users who are using Drag & Drop action icons, or still learning GML, can get help from more experienced members.

Please READ the Novice Q&A Forum Rules prior to posting. And remember that the General GMC Rules apply here too.

 
Reply to this topicStart new topic
Need Help With Code For Sound, only one sound will play
Dr. Zeus
post Nov 7 2009, 01:26 PM
Post #1


GMC Member
Group Icon

Group: GMC Member
Posts: 25
Joined: 5-May 09
Member No.: 132872



In my game I am trying to have it so when you are in certain places (cities, towns dungeons ect..) it will play a certain background music. However when your not in these places I want for there to be a generic background music playing. I wrote a code for this but the music will not switch when you get close to town.

My Code:

object: ctn_sound

Create event:

{

global.sound = 1

}

Step event:

{

if (global.sound = 0){ //if sound is off turn off background music
sound_stop(snd_World)
sound_stop(snd_Village)
exit;
}

else if (global.sound = 1){ //play snd_World
sound_loop(snd_World)
global.sound = 2
exit;
}

else if (global.sound = 3){ //play snd_Village
sound_loop(snd_Village)
global.sound = 4
exit;
}

}

object: ctn_(snd_village)

Step event:

{

if (global.sound = 0){ //if sound is off do nothing
exit;
}

else if (global.sound != 4) and (distance_to_object(obj_hero) < 600){ //if snd_village is not playing and distance to village is less than 600 play snd_Village
global.sound = 3
exit;
}

else if (global.sound = 4) and (distance_to_object(obj_hero) > 600){ //if snd_village is playing and distance to village is greater than 600 play snd_World
global.sound = 1
exit;
}

else{
exit;
}

}


This code displays no error messages and for some reason will only play snd_World even if you are within proximity of the village. Ctn_(snd_Village) is located within the town i am testing this in.
Go to the top of the page
 
+Quote Post
FoxInABox
post Nov 7 2009, 02:44 PM
Post #2


GMC Member
Group Icon

Group: GMC Member
Posts: 2680
Joined: 15-December 06
From: Norway
Member No.: 66159



try draw the distance between player and the object, and you will be surpriced:
CODE
draw_text(0,0,string(distance_to_object(obj_hero)))


the reason for the huge distance seems to be because it uses the sprites it got to find the distance, and since your sound object don't have one.. well, then it thinks it's pretty far away..

you can either give it a sprite and set visible to false.. or use point_distance(x,y,obj_hero.x,obj_hero.y)
Go to the top of the page
 
+Quote Post
Dr. Zeus
post Nov 7 2009, 11:24 PM
Post #3


GMC Member
Group Icon

Group: GMC Member
Posts: 25
Joined: 5-May 09
Member No.: 132872



Thanks a lot. I just gave ctn_(snd_village) a sprite made it invisible and now it works great. Tyvm!
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



RSS Lo-Fi Version Time is now: 22nd November 2009 - 11:50 AM