Why does this function not work?

Posted By: Loremaster

Why does this function not work? - 03/25/13 21:51

Code:
function playMusic() {
		if (event_type ==EVENT_SCAN && you==player) {								//The Player entity has scanned me
			if (media_playing(nMusicHandle) == 0) {									//Only play me if there is no music
				nMusicHandle = media_play(sMusicTitle, NULL, nMusicVol);
			}
			else {
				showDialog("Music Handler in use.");									//DEBUG CONDITION
			}
		}
   }



It is supposed to start the function as soon as the player scans the object. If already a track is playing (handler > 0), none should be played. Actually it starts the track over and over again, playing it in dissonance as long as the player scans the object.

I can only imagine I use the condition wrong, but that's what I ttok from the manual.
Posted By: 3run

Re: Why does this function not work? - 03/25/13 22:07

Try to insert beep(); before and after each comparision, to find which one doesn't work.. That will help you to find out the problem yourself laugh
Posted By: Loremaster

Re: Why does this function not work? - 03/25/13 22:41

I know that it meets the condition every time. Which it shouldn't. media_playing should return the current frame, therefore be >0 as soon as the title starts.

But it isn't.
Posted By: MasterQ32

Re: Why does this function not work? - 03/26/13 01:22

try to use some kind of "music manager".
this doesn't have to be more than one function which just fades between different songs and your event just has to set a variable to the correct music id.
Posted By: Uhrwerk

Re: Why does this function not work? - 03/26/13 01:29

How did you define nMusicHandle ?
Posted By: Loremaster

Re: Why does this function not work? - 03/26/13 02:09

Code:
#define musType skill1 				
#define musID skill2		

int nMusicVol = 100;																			//Must be handled by the Game-Settings later.
int nMusicHandle = 0;																		//Mediahandle for all things related to music.	
STRING* sMusicTitle;			 																



///////////////////////
//
//PICKING AND PLAYING THE MUSIC
//
///////////////////////

function playMusic() {
	if (media_playing(nMusicHandle)==0) {												//Only play me if there is no music
				nMusicHandle = media_play(sMusicTitle, NULL, nMusicVol);
	}
}
    
function pickMusic(){																		
  	if (event_type ==EVENT_SCAN && you==player) {									//The Player entity has scanned me
	switch(my.musID) {																		//musID-Skill determines, which song to play
		case 1:
			sMusicTitle = "Musik\\stealth2.mp3";
			break;
		case 2:
			sMusicTitle = "Musik\\stealth1.mp3";
			break;
		case 3:
			sMusicTitle = "Musik\\scene1.mp3";
			break;
		default:																					//Fallback: If something goes wrong, we play the most generic stealth
			sMusicTitle = "Musik\\stealth1.mp3";										//music we have. Can't be too inappropriate.
		}
	playMusic();
	}
}

// skill1: musType 0
// help: default 0 = Ambient, 1 = Scene, 2 = Action
// skill2: musID 1
// help: Refer to the tracklist I gave you
action triggerMusic() {
	my.emask |= ENABLE_SCAN;																//I will react when being scanned
	my.event = pickMusic;
	my.skill60 = 20; 																			//me is some kind of trigger. me happy.
	set (my,INVISIBLE);
	set (my,PASSABLE);
}

Posted By: Loremaster

Re: Why does this function not work? - 03/26/13 02:17

Saw it myself.

int. redeclared to var and voilą. That was a VERY insigthful question, Uhrwerk. Thank you once again.
Posted By: Uhrwerk

Re: Why does this function not work? - 03/26/13 13:22

I'm glad I could help. ^^
© 2024 lite-C Forums