let bgm = ObjSound_Create;
let bgm2 = ObjSound_Create;
let bgm3 = ObjSound_Create;
let bgma = [bgm,bgm2,bgm3];
let GCSD = GetCurrentScriptDirectory();
let sound = [];
let path1 = GCSD ~ "bgm/meem/meem1.ogg";
let path2 = GCSD ~ "bgm/meem/meem2.mp3";
let path3 = GCSD ~ "bgm/meem/meem3.ogg";
let paths = [path1, path2, path3];

SetCommonData("Memery", 0);

@Initialize{
	sound = [
		CreateSound(GCSD ~ "/se/smbullet.wav"), 	//index = 0
		CreateSound(GCSD ~ "/se/labullet.wav"),	 	//index = 1
		CreateSound(GCSD ~ "/se/spirit.wav"),	 	//index = 2
		CreateSound(GCSD ~ "/se/damage1.wav"),	 	//index = 3
		CreateSound(GCSD ~ "/se/damage2.wav"),	 	//index = 4
		CreateSound(GCSD ~ "/se/timeout.wav"),		//index = 5
		CreateSound(GCSD ~ "/se/timeout2.wav"),		//index = 6
		CreateSound(GCSD ~ "/se/explode.wav"),		//index = 7
		CreateSound(GCSD ~ "/se/explodebig.wav"),	//index = 8
		CreateSound(GCSD ~ "/se/charge.wav"),		//index = 9
		CreateSound(GCSD ~ "/se/item.wav"),			//index = 10
		CreateSound(GCSD ~ "/se/extend.wav"),		//index = 11
		CreateSound(GCSD ~ "/se/bombget.wav"),		//index = 12
		CreateSound(GCSD ~ "/se/len/smbullet.wav"),	//index = 13
		CreateSound(GCSD ~ "/se/len/labullet.wav"),	//index = 14
		CreateSound(GCSD ~ "/se/len/smlaser.wav"),	//index = 15
		CreateSound(GCSD ~ "/se/len/lalaser.wav"),	//index = 16
		CreateSound(GCSD ~ "/se/len/summon.wav"),	//index = 17
		CreateSound(GCSD ~ "/se/len/warning.wav"),	//index = 18
		CreateSound(GCSD ~ "/se/meem/spawn.wav"),	//index = 19
		CreateSound(GCSD ~ "/se/meem/fire.wav"),	//index = 20
		CreateSound(GCSD ~ "/se/meem/fly.wav"),		//index = 21
	];
	SetCommonData("SoundScript", GetOwnScriptID);
	BGM;
}

@Event{
    alternative(GetEventType())
    case(EV_PAUSE_ENTER){
        if(GetCommonData("Memery", 0) == 0){
		ObjSound_Stop(bgma[0]);
		}
        if(GetCommonData("Memery", 0) == 1){
		ObjSound_Stop(bgma[1]);
		}
        if(GetCommonData("Memery", 0) == 2){
		ObjSound_Stop(bgma[2]);
		}
    }
    case(EV_PAUSE_LEAVE){
        if(GetCommonData("Memery", 0) == 0){
		ObjSound_Play(bgma[0]);
		}
        if(GetCommonData("Memery", 0) == 1){
		ObjSound_Play(bgma[1]);
		}
        if(GetCommonData("Memery", 0) == 2){
		ObjSound_Play(bgma[2]);
		}
    }
	case(EV_USER){
		let arg = GetEventArgument(0);
		ObjSound_Play(sound[arg[0]]);
		ObjSound_SetVolumeRate(sound[arg[0]], arg[1]/2);
	}
	case(EV_USER+1){//SWITCH
		ObjSound_Stop(bgma[0]);
		ObjSound_Play(bgma[1]);
	}
	case(EV_USER+2){//SWITCH
		ObjSound_Stop(bgma[0]);
		ObjSound_Stop(bgma[1]);
		ObjSound_Play(bgma[2]);
	}
	case(EV_USER+3){//SWITCH
		ObjSound_Stop(bgma[2]);
	}
}

function CreateSound(path){
	let obj = ObjSound_Create();
	ObjSound_Load(obj, path);
	ObjSound_SetVolumeRate(obj, 100);
	ObjSound_SetLoopEnable(obj, false);
	ObjSound_SetSoundDivision(obj, SOUND_SE);
	return obj;
}

task BGM{
ascent(i in 0..3){
ObjSound_Load(bgma[i],paths[i]); 
ObjSound_SetSoundDivision(bgma[i], SOUND_BGM);
ObjSound_SetLoopEnable(bgma[i],true); 
ObjSound_SetRestartEnable(bgma[i], true);}
ObjSound_SetVolumeRate(bgma[0],70);
ObjSound_SetVolumeRate(bgma[1],100);
ObjSound_SetLoopEnable(bgma[2],false); 
ObjSound_Play(bgma[0]);
}