Jump to content

Photo

ScreenChanged.zh - Check if the Screen Has Changed, and How...


  • Please log in to reply
3 replies to this topic

#1 Timelord

Timelord

    The Timelord

  • Banned
  • Location:Prydon Academy

Posted 18 September 2016 - 07:55 AM

I thought I'd share this here: It's a small header for checking if the screen changes, using Link->Misc[] instead of global variables, or arrays.
 
 
////////////////////////
/// ScreenChanged.zh ///
/// By: ZoriaRPG     ///
/// v0.4             ///
/// 18th Sept, 2016  ///
////////////////////////

const int LINK_MISC_SCREENCHANGES = 10;  //Link->Misc[index] that we're using to track screen changes. 

//////////////////////
/// CORE FUNCTIONS ///
//////////////////////

//Returns if the screen has changed, and we use that in the global active while loop, 
//before Waitdraw() to automate the process. 
bool ScreenChanged(){
	int a[3];
	a[0] = Link->Misc[LINK_MISC_SCREENCHANGES] << 0; //CurScreen
	a[1] = ( Link->Misc[LINK_MISC_SCREENCHANGES] - ( Link->Misc[LINK_MISC_SCREENCHANGES] << 0 ) ) *10000; //CurDMap
	if ( Game->GetCurScreen() != a[0] && Game->GetCurDMap() != a[1] ) return true;
	return false;	
}

//Call before the while loop in the global active script.
//This is also called with ScreenChanged() to update the screen information. 
void UpdateScreenChanges(){
	a[0] = Game->GetCurScreen();
	a[1] = Game->GetCurDMap();
	a[2] = a[0] + ( a[1] / 10000 ); 
	Link->Misc[LINK_MISC_SCREENCHANGES] = a[2];
}

/////////////////////////
/// UTILITY FUNCTIONS ///
/////////////////////////

//! Functions to call in scripts, to perform actions based on if the screen has changed.
//! You may optionally check how it changed (scrolling, or warp), and you may optionally force an update.

//Returns if the screen has changed in general, and optionally forces an update.
bool ScreenChanged(bool update){
	int a[3];
	a[0] = Link->Misc[LINK_MISC_SCREENCHANGES] << 0; //CurScreen
	a[1] = ( Link->Misc[LINK_MISC_SCREENCHANGES] - ( Link->Misc[LINK_MISC_SCREENCHANGES] << 0 ) ) *10000; //CurDMap
	if ( Game->GetCurScreen() != a[0] && Game->GetCurDMap() != a[1] ) {
		if ( update ) UpdateScreenChanges(LINK_MISC_SCREENCHANGES);
		return true;
	}
	return false;
}

//Returns if the screen changed by scrolling, and optionally forces an update.
bool ScreenScrolled(bool update){
	int a[3];
	a[0] = Link->Misc[LINK_MISC_SCREENCHANGES] << 0; //CurScreen
	a[1] = ( Link->Misc[LINK_MISC_SCREENCHANGES] - ( Link->Misc[LINK_MISC_SCREENCHANGES] << 0 ) ) *10000; //CurDMap
	if ( Game->GetCurScreen() != a[0] && Game->GetCurDMap() != a[1] && Link->Action == LA_SCROLLING ) {
		if ( update ) UpdateScreenChanges(LINK_MISC_SCREENCHANGES);
		return true;
	}
	return false;
}

//Returns if the screen changed without scrolling, and optionally forces an update.
bool ScreenChangedWarp(bool update){
	int a[3];
	a[0] = Link->Misc[LINK_MISC_SCREENCHANGES] << 0; //CurScreen
	a[1] = ( Link->Misc[LINK_MISC_SCREENCHANGES] - ( Link->Misc[LINK_MISC_SCREENCHANGES] << 0 ) ) *10000; //CurDMap
	if ( Game->GetCurScreen() != a[0] && Game->GetCurDMap() != a[1] && Link->Action != LA_SCROLLING ) {
		if ( update ) UpdateScreenChanges(LINK_MISC_SCREENCHANGES);
		return true;
	}
	return false;
}

//Returns if the screen changed by scrolling.
bool ScreenScrolled(bool update){
	int a[3];
	a[0] = Link->Misc[LINK_MISC_SCREENCHANGES] << 0; //CurScreen
	a[1] = ( Link->Misc[LINK_MISC_SCREENCHANGES] - ( Link->Misc[LINK_MISC_SCREENCHANGES] << 0 ) ) *10000; //CurDMap
	if ( Game->GetCurScreen() != a[0] && Game->GetCurDMap() != a[1] && Link->Action == LA_SCROLLING ) return true;
	return false;
}

//Returns if the screen changed without scrolling. 
bool ScreenChangedWarp(bool update){
	int a[3];
	a[0] = Link->Misc[LINK_MISC_SCREENCHANGES] << 0; //CurScreen
	a[1] = ( Link->Misc[LINK_MISC_SCREENCHANGES] - ( Link->Misc[LINK_MISC_SCREENCHANGES] << 0 ) ) *10000; //CurDMap
	if ( Game->GetCurScreen() != a[0] && Game->GetCurDMap() != a[1] && Link->Action != LA_SCROLLING ) return true;
	return false;
}

//! Example Global Active Script
global script ChangedScreen{
	void run(){
		UpdateScreenChanges(); //Initialise the values at the start of each game.
		while(true){
			if ( ScreenChanged() ) UpdateScreenChanges();
			Waitdraw();
			Waitframe();
		}
	}
}
Essentially untested, but barring typos, it should work, and I'll eventually drop it to the database.

Edited by ZoriaRPG, 18 September 2016 - 08:06 AM.

  • coolgamer012345 likes this

#2 idontknow8

idontknow8

    Senior

  • Members

Posted 18 September 2016 - 05:46 PM

Ok, so this could be used to detect if Link came to a screen via a warp,set his Z value to high a value and then every frame, decrease it until it reaches zero? (Simulating him falling into the screen, as if falling down a hole or pit?). If so, how would I go about using this?

#3 Timelord

Timelord

    The Timelord

  • Banned
  • Location:Prydon Academy

Posted 19 September 2016 - 03:46 AM

You could.

It boccurs to me that the user may want to update after Waitdraw(), and further, that a global script isn't mandatory.b If all the user needs to check is that the screen differs from the last time it was checked, they caqn do that with an ffc.

In general, you'd just call if ( ScreenChangedWarp() ) in your code to do what you want. Pertty much, as long as you call UpdateScreenChanges(), to store the last values, you ca detect if a screen change has occurred.

I considered making flags that update one frame late, to denote how the screen last changed. That sort of thing would allow more precise detection of changes by type (scrolling, or warp). Note that scrolling side warps will return as scrolling in this case.

I'll see if I can hash out some extra content for that.

FWIW, I'd set a flag on Link->Misc[] with your warp ffc, to detect that it sent him somewhere. Tat's the best way to handle knowing the source of the change, in the example that you provided.

--------

What sorts of things would users want this to do, that it doesn't do at present?

#4 Timelord

Timelord

    The Timelord

  • Banned
  • Location:Prydon Academy

Posted 19 September 2016 - 10:03 AM

Here's where I'm leaving it off for the day...

ScreenChanged.zh v0.4.2


Edited by ZoriaRPG, 19 September 2016 - 10:07 AM.



0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users