ID:270271
 
how would i make it so it's playing music but when i enter a cave the music changes and changes back when i leave the cave?
turf/door/cavedoor
icon = 'blah.dmi'
icon_state = "blah"
Enter(mob/M) //when the mob enters the turf
M << sound(null) //stop music manually
M << sound('blah.mid') //play the other, put a ,1 after the sound file if you want it to repeat.


Do the same thing for leaving the cave.
In response to Pyro_dragons
Not Enter(). Entered().
In response to Jon88
My bad, but does it really matter all the much? I've been wondering that.
In response to Pyro_dragons
Pyro_dragons wrote:
My bad, but does it really matter all the much? I've been wondering that.

It does. Enter() is completely different from Entered().
Enter() should contain code that has to do with, "Can a mob/obj enter this?". Entered() is for code that should run once that's already certain, and has happened.

Your code, for example, would fail to work, since you neglected to return 1 or 0, to say if the movement should be allowed or not.
In response to Jon88
Erhm, he just wanted to know how to do music. I just added that in as a quick little thing. Of course it won't work, it's not supposed to. It's just an example of how music would work. But yeah, change it to Entered(), that's my fault.
In response to Pyro_dragons
Another good reason is that Enter() is often used in other code to check if you can enter something, without moving into it. Pathfinding algorithms might use it, for example.

You don't want the music to trigger because a pathfinding algorithm checked whether you could enter that square.

Finally, it would still start playing if you failed to enter the square - say, someone else was standing on it.
In response to Jp
it wont workit says that m<<sound(null) and the 1 below it are errored

turf/Teleorter/Teleorter3
icon = 'teli3.dmi'
icon_state = ""
Entered(mob/m)
M << sound(null) Error.
M << sound('bgmusic.mid1') Error.
In response to Stone_Cold_Oven
You passed mob/m as an argument and are using M. Case sensitive!
In response to Mysame
so what should i put for it to work?