Jump to content

Photo

Variable does not update


  • Please log in to reply
1 reply to this topic

#1 Emily

Emily

    Scripter / Dev

  • ZC Developers

Posted 31 July 2018 - 03:50 AM

Okay, lot of code:

import "std.zh"
//start OcarinaScripts
//CTRL+F for "//CHANGE//" to find things that must be changed for the script to function. CTRL+F "//CUSTOMSONG//" to find the places that must be changed to add custom songs.
//start GLOBAL SampleGlobal
//A combo representing the pressed button, with a transparent background //CHANGE//
const int NOTECOMBO_A = 261;
const int NOTECOMBO_DOWN = 269;
const int NOTECOMBO_RIGHT = 268;
const int NOTECOMBO_LEFT = 270;
const int NOTECOMBO_UP = 271;
//The CSet to draw the given combo in //CHANGE//
const int NOTECSET_A = 0;
const int NOTECSET_DOWN = 0;
const int NOTECSET_RIGHT = 0;
const int NOTECSET_LEFT = 0;
const int NOTECSET_UP = 0;
//Sound FX to play if the played song is not a valid song //CHANGE//
const int SFX_ERROR = 0;
//List of songs:
int SONGNOTES_SongOfTime[] = {3,1,2,3,1,2,0,0};
int SONGNOTES_ZeldasLullaby[] = {4,5,3,4,5,3,0,0};
int SONGNOTES_EponasSong[] = {5,4,3,5,4,3,0,0};
int SONGNOTES_SariasSong[] = {2,3,4,2,3,4,0,0};
int SONGNOTES_SongOfStorms[] = {1,2,5,1,2,5,0,0};
int SONGNOTES_SunSong[] = {3,2,5,3,2,5,0,0};
int SONGNOTES_MinuetOfForest[] = {1,5,4,3,4,3,0,0};
int SONGNOTES_BoleroOfFire[] = {2,1,2,1,3,2,3,2};
int SONGNOTES_SerenadeOfWater[] = {1,2,3,3,4,0,0,0};
int SONGNOTES_NocturneOfShadow[] = {4,3,3,1,4,3,2,0};
int SONGNOTES_RequiemOfSpirit[] = {1,2,1,3,2,1,0,0};
int SONGNOTES_PreludeOfLight[] = {5,3,5,3,4,5,0,0};
int SONGNOTES_GoronsLullaby[] = {1,3,4,1,3,4,3,1};
int SONGNOTES_OathToOrder[] = {3,2,1,2,3,5,0,0};
int SONGNOTES_SongOfSoaring[] = {2,4,5,2,4,5,0,0};
int SONGNOTES_SongOfHealing[] = {4,3,2,4,3,2,0,0};
int SONGNOTES_ElegyOfEmptiness[] = {3,4,3,2,3,5,4,0};
int SONGNOTES_NewWaveBossaNova[] = {4,5,4,3,2,4,3,0};
int SONGNOTES_SongOfDoubleTime[] = {3,3,1,1,2,2,0,0};
int SONGNOTES_SongOfInvertedTime[] = {2,1,3,2,1,3,0,0};
//Add custom songs:
//Put a name directly after the underscore, and numbers for notes in each spot.
//A=1,DOWN=2,RIGHT=3,LEFT=4,UP=5, and if the song is less than 8 notes, fill the ending spots with 0s. The // before the line of code must also be removed for the song to function.
//int[] SONGNOTES_ = {,,,,,,,};
//Song indexes
const int SONG_SongOfTime = 0;
const int SONG_ZeldasLullaby = 1;
const int SONG_EponasSong = 2;
const int SONG_SariasSong = 3;
const int SONG_SongOfStorms = 4;
const int SONG_SunSong = 5;
const int SONG_MinuetOfForest = 6;
const int SONG_BoleroOfFire = 7;
const int SONG_SerenadeOfWater = 8;
const int SONG_NocturneOfShadow = 9;
const int SONG_RequiemOfSpirit = 10;
const int SONG_PreludeOfLight = 11;
const int SONG_GoronsLullaby = 12;
const int SONG_OathToOrder = 13;
const int SONG_SongOfSoaring = 14;
const int SONG_SongOfHealing = 15;
const int SONG_ElegyOfEmptiness = 16;
const int SONG_NewWaveBossaNova = 17;
const int SONG_SongOfDoubleTime = 18;
const int SONG_SongOfInvertedTime = 19;
//CUSTOMSONG// Add your song's ID, which should simply be 20, 21, etc. for each custom song.
//Song SoundFX IDs -- set these to the number of the SFX you want to play, which should include the actual song playing.
const int SONGSOUND_SongOfTime = 200;
const int SONGSOUND_ZeldasLullaby = 201;
const int SONGSOUND_EponasSong = 202;
const int SONGSOUND_SariasSong = 203;
const int SONGSOUND_SongOfStorms = 204;
const int SONGSOUND_SunSong = 205;
const int SONGSOUND_MinuetOfForest = 206;
const int SONGSOUND_BoleroOfFire = 207;
const int SONGSOUND_SerenadeOfWater = 208;
const int SONGSOUND_NocturneOfShadow = 209;
const int SONGSOUND_RequiemOfSpirit = 210;
const int SONGSOUND_PreludeOfLight = 211;
const int SONGSOUND_GoronsLullaby = 212;
const int SONGSOUND_OathToOrder = 213;
const int SONGSOUND_SongOfSoaring = 214;
const int SONGSOUND_SongOfHealing = 215;
const int SONGSOUND_ElegyOfEmptiness = 216;
const int SONGSOUND_NewWaveBossaNova = 217;
const int SONGSOUND_SongOfDoubleTime = 218;
const int SONGSOUND_SongOfInvertedTime = 219;
//CUSTOMSONG//Add your custom song SFX ids the same as the normal ones.
//Learned songs- if you add a song, you must add to the number in the squarebrackets; it must be equal to the total number of songs! //CUSTOMSONG//
bool LEARNED_SONGS[20];
//Constants
const int NOTE_A = 1;
const int NOTE_DOWN = 2;
const int NOTE_RIGHT = 3;
const int NOTE_LEFT = 4;
const int NOTE_UP = 5;
const int NULL_NOTE = 0;
const int FRAMESOFSONGFREEZE = 100;
//Variables
bool ocarina_mode = false;
int ocIndex = 0;
int currSong[8];
int playedSong = -1;
//
global script SampleGlobal{
	int songFrames = 0;
	void ocarina(){
		bool doDraw = true;

		if(Link->PressA){
			currSong[ocIndex] = NOTE_A;
			ocIndex++;
		} else if(Link->PressDown) {
			currSong[ocIndex] = NOTE_DOWN;
			ocIndex++;
		} else if(Link->PressRight) {
			currSong[ocIndex] = NOTE_RIGHT;
			ocIndex++;
		} else if(Link->PressLeft) {
			currSong[ocIndex] = NOTE_LEFT;
			ocIndex++;
		} else if(Link->PressUp) {
			currSong[ocIndex] = NOTE_UP;
			ocIndex++;
		}
		
		if(ocIndex!=8 && playSong(currSong)){
			songFrames = 100;
			doDraw = false;
			ocarina_mode = false;
			for(;ocIndex<8;ocIndex++){}
			NoAction();
		} else if (ocIndex==8){
			if(playSong(currSong)){
				songFrames = 100;
				doDraw = false;
				ocarina_mode = false;
			} else {
				ocarina_mode = false;
				Game->PlaySound(SFX_ERROR);
				playedSong = -1;
			}
		}
		
		drawNotes(doDraw);
		NoAction();
	}
	
	void drawNotes(bool draw){
		if(draw){
			for(int note=0;note<8;note++){
				if(currSong[note]==0){
					Screen->FastCombo(6,64+(16*note),48,0,0,128);
				} else if(currSong[note]==1){
					Screen->FastCombo(6,64+(16*note),48,NOTECOMBO_A,NOTECSET_A,128);
				} else if(currSong[note]==2){
					Screen->FastCombo(6,64+(16*note),48,NOTECOMBO_DOWN,NOTECSET_DOWN,128);
				} else if(currSong[note]==3){
					Screen->FastCombo(6,64+(16*note),48,NOTECOMBO_RIGHT,NOTECSET_RIGHT,128);
				} else if(currSong[note]==4){
					Screen->FastCombo(6,64+(16*note),48,NOTECOMBO_LEFT,NOTECSET_LEFT,128);
				} else if(currSong[note]==5){
					Screen->FastCombo(6,64+(16*note),48,NOTECOMBO_UP,NOTECSET_UP,128);
				}
			}
		} else {
			for(int note=0;note<8;note++){
				Screen->FastCombo(6,64+(16*note),48,0,0,128);
			}
		}
	}
	
	bool playSong(int song){
		if(LEARNED_SONGS[SONG_SongOfTime] && compareSongs(song,SONGNOTES_SongOfTime)){
			Game->PlaySound(SONGSOUND_SongOfTime);
			playedSong=SONG_SongOfTime;
		} else if(LEARNED_SONGS[SONG_ZeldasLullaby] && compareSongs(song,SONGNOTES_ZeldasLullaby)){
			Game->PlaySound(SONGSOUND_ZeldasLullaby);
			playedSong=SONG_ZeldasLullaby;
		} else if(LEARNED_SONGS[SONG_EponasSong] && compareSongs(song,SONGNOTES_EponasSong)){
			Game->PlaySound(SONGSOUND_EponasSong);
			playedSong=SONG_EponasSong;
		} else if(LEARNED_SONGS[SONG_SariasSong] && compareSongs(song,SONGNOTES_SariasSong)){
			Game->PlaySound(SONGSOUND_SariasSong);
			playedSong=SONG_SariasSong;
		} else if(LEARNED_SONGS[SONG_SongOfStorms] && compareSongs(song,SONGNOTES_SongOfStorms)){
			Game->PlaySound(SONGSOUND_SongOfStorms);
			playedSong=SONG_SongOfStorms;
		} else if(LEARNED_SONGS[SONG_SunSong] && compareSongs(song,SONGNOTES_SunSong)){
			Game->PlaySound(SONGSOUND_SunSong);
			playedSong=SONG_SunSong;
		} else if(LEARNED_SONGS[SONG_MinuetOfForest] && compareSongs(song,SONGNOTES_MinuetOfForest)){
			Game->PlaySound(SONGSOUND_MinuetOfForest);
			playedSong=SONG_MinuetOfForest;
		} else if(LEARNED_SONGS[SONG_BoleroOfFire] && compareSongs(song,SONGNOTES_BoleroOfFire)){
			Game->PlaySound(SONGSOUND_BoleroOfFire);
			playedSong=SONG_BoleroOfFire;
		} else if(LEARNED_SONGS[SONG_SerenadeOfWater] && compareSongs(song,SONGNOTES_SerenadeOfWater)){
			Game->PlaySound(SONGSOUND_SerenadeOfWater);
			playedSong=SONG_SerenadeOfWater;
		} else if(LEARNED_SONGS[SONG_NocturneOfShadow] && compareSongs(song,SONGNOTES_NocturneOfShadow)){
			Game->PlaySound(SONGSOUND_NocturneOfShadow);
			playedSong=SONG_NocturneOfShadow;
		} else if(LEARNED_SONGS[SONG_RequiemOfSpirit] && compareSongs(song,SONGNOTES_RequiemOfSpirit)){
			Game->PlaySound(SONGSOUND_RequiemOfSpirit);
			playedSong=SONG_RequiemOfSpirit;
		} else if(LEARNED_SONGS[SONG_PreludeOfLight] && compareSongs(song,SONGNOTES_PreludeOfLight)){
			Game->PlaySound(SONGSOUND_PreludeOfLight);
			playedSong=SONG_PreludeOfLight;
		} else if(LEARNED_SONGS[SONG_GoronsLullaby] && compareSongs(song,SONGNOTES_GoronsLullaby)){
			Game->PlaySound(SONGSOUND_GoronsLullaby);
			playedSong=SONG_GoronsLullaby;
		} else if(LEARNED_SONGS[SONG_OathToOrder] && compareSongs(song,SONGNOTES_OathToOrder)){
			Game->PlaySound(SONGSOUND_OathToOrder);
			playedSong=SONG_OathToOrder;
		} else if(LEARNED_SONGS[SONG_SongOfSoaring] && compareSongs(song,SONGNOTES_SongOfSoaring)){
			Game->PlaySound(SONGSOUND_SongOfSoaring);
			playedSong=SONG_SongOfSoaring;
		} else if(LEARNED_SONGS[SONG_SongOfHealing] && compareSongs(song,SONGNOTES_SongOfHealing)){
			Game->PlaySound(SONGSOUND_SongOfHealing);
			playedSong=SONG_SongOfHealing;
		} else if(LEARNED_SONGS[SONG_ElegyOfEmptiness] && compareSongs(song,SONGNOTES_ElegyOfEmptiness)){
			Game->PlaySound(SONGSOUND_ElegyOfEmptiness);
			playedSong=SONG_ElegyOfEmptiness;
		} else if(LEARNED_SONGS[SONG_NewWaveBossaNova] && compareSongs(song,SONGNOTES_NewWaveBossaNova)){
			Game->PlaySound(SONGSOUND_NewWaveBossaNova);
			playedSong=SONG_NewWaveBossaNova;
		} else if(LEARNED_SONGS[SONG_SongOfDoubleTime] && compareSongs(song,SONGNOTES_SongOfDoubleTime)){
			Game->PlaySound(SONGSOUND_SongOfDoubleTime);
			playedSong=SONG_SongOfDoubleTime;
		} else if(LEARNED_SONGS[SONG_SongOfInvertedTime] && compareSongs(song,SONGNOTES_SongOfInvertedTime)){
			Game->PlaySound(SONGSOUND_SongOfInvertedTime);
			playedSong=SONG_SongOfInvertedTime;
		}//Add another else/if here for custom songs! //CUSTOMSONG//
	}
	
	void activateSong(int song){
		if(song==SONG_SongOfTime){
			//INSERT CODE//Do something here when Song of Time is played!
		} else if(song==SONG_ZeldasLullaby){
			//INSERT CODE//Do something here when Zelda's Lullaby is played!
		} else if(song==SONG_EponasSong){
			//INSERT CODE//Do something here when Epona's Song is played!
		} else if(song==SONG_SariasSong){
			//INSERT CODE//Do something here when Saria's Song is played!
		} else if(song==SONG_SongOfStorms){
			//INSERT CODE//Do something here when Song of Storms is played!
		} else if(song==SONG_SunSong){
			//INSERT CODE//Do something here when Sun's Song is played!
		} else if(song==SONG_MinuetOfForest){
			//INSERT CODE//Do something here when Minuet of Forest is played!
		} else if(song==SONG_BoleroOfFire){
			//INSERT CODE//Do something here when Bolero of Fire is played!
		} else if(song==SONG_SerenadeOfWater){
			//INSERT CODE//Do something here when Serenade of Water is played!
		} else if(song==SONG_NocturneOfShadow){
			//INSERT CODE//Do something here when Nocturne of Shadow is played!
		} else if(song==SONG_RequiemOfSpirit){
			//INSERT CODE//Do something here when Requiem of Spirit is played!
		} else if(song==SONG_PreludeOfLight){
			//INSERT CODE//Do something here when Prelude of Light is played!
		} else if(song==SONG_GoronsLullaby){
			//INSERT CODE//Do something here when Goron's Lullaby is played!
		} else if(song==SONG_OathToOrder){
			//INSERT CODE//Do something here when Oath to Order is played!
		} else if(song==SONG_SongOfSoaring){
			//INSERT CODE//Do something here when Song of Soaring is played!
		} else if(song==SONG_SongOfHealing){
			//INSERT CODE//Do something here when Song of Healing is played!
		} else if(song==SONG_ElegyOfEmptiness){
			//INSERT CODE//Do something here when Elegy of Emptiness is played!
		} else if(song==SONG_NewWaveBossaNova){
			//INSERT CODE//Do something here when New Wave Bossa Nova is played!
		} else if(song==SONG_SongOfDoubleTime){
			//INSERT CODE//Do something here when Song of Double Time is played!
		} else if(song==SONG_SongOfInvertedTime){
			//INSERT CODE//Do something here when Song of Inverted Time is played!
		}//Add another else/if here for custom songs! //CUSTOMSONG// (Not REQUIRED if you just want it to trigger the FFC secrets script)
	}
	
	bool compareSongs(int song, int song2){
		for(int note=0;note<8;note++){
			if(song[note]==song2[note]){
				//Continue
			} else {
				return false;
			}
		}
		return true;
	}
	
	void run(){
		while(true){
			if(songFrames>0){
				Trace(songFrames);
			}
			if(playedSong>-1){
				ocarina_mode = false;
			}
			if(songFrames>0){
				ocarina_mode = false;
				NoAction();
				songFrames;
				if(songFrames==0){
					activateSong(playedSong);
					playedSong=-1;
				}
			} else if(ocarina_mode){
				ocarina();
			}
			Waitdraw();
			Waitframe();
		}
	}
	
}
//end SampleGlobal
//start ITEM Ocarina
item script Ocarina{
	//
	//Set this to the item you wish to activate song mode. This item should be a Custom Item Class.
	//
	void run(){
		for(int note = 0;note<8;note++){
			currSong[note]=0;
		}
		ocIndex = 0;
		playedSong=-1;
		ocarina_mode = true;
	}
}
//end Ocarina
//start FFC SongTriggersSecrets
ffc script SongTriggersSecrets{
	//
	//Var 0: Number of song to require for secret trigger
	//Var 1: Set to 0 for temporary secrets, set to 1 for permanent secrets.
	//
	//
	void run(int song, bool perm){
		bool waiting = true;
		while(waiting){
			if(playedSong==song){
				Screen->TriggerSecrets();
				if(perm){
					Screen->State[ST_SECRET] = true;
				}
				waiting=false;
			}
			Waitframe();
		}
	}
}
//end SongTriggersSecrets
//start FFC LearnASong
ffc script LearnASong{
	//
	//Var 0: Number of song to learn when stepping on this tile
	//Note that the combo for this FFC will be automatically set to Combo 0 once the song is learned!
	//
	void run(int song){
		bool waiting = true;
		while(waiting){
			if(Link->X>this->X-8&&Link->X<this->X+8&&Link->Y>this->Y-8&&Link->Y<this->Y+8){
				LEARNED_SONGS[song]=true;
			}
			if(LEARNED_SONGS[song]){
				waiting=false;
				this->Data=0;
			}
			Waitframe();
		}
	}
}
//end LearnASong
//end OcarinaScripts

Every single part of this script works thus far- I have only tested the Song of Time, but it recognizes the note pattern fine for it, playing the specified sound FX. There is ONE issue and I have been troubleshooting for like 3 hours now.

 

int songFrames is ALWAYS 0. It never updates. It should be set to 100 when the song plays. The song plays and does everything it should, EXCEPT for updating the ONE variable. This means that the portion of "void run()" within the SampleGlobal script does not freeze the player while the song SFX is playing as it should. The Trace(songFrames); with the condition (songFrames>0) never traces anything, though when removing the conditional it traces 0 repeatedly. I cannot figure out for the life of me why this variable does not update.

 

For the record, the variable was originally defined on the line below playedSong's definition, and it was not working. It was moved where it is now as a random attempt at fixing it. 

 

Anyone have any ideas as to why this doesn't update?



#2 Emily

Emily

    Scripter / Dev

  • ZC Developers

Posted 31 July 2018 - 08:14 AM

Nevermind. Nevermind everything. I FORGOT THE DAMN RETURN TRUE STATEMENTS IN playSong() SO IT NEVER EXECUTED THE IF STATEMENT. DERP DERP DERP DERP.

 

...on the bright side if you are interested in this script it should be done and ready for release to the database soon....




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users