Posted by member 12798 on 2004-01-16 17:32:28
This is a simple script which provides hotspot functionality. It simply checks if the mouse is located inside a certain area. Nothing spectacular, especially not the code ... however, maybe somebody finds it helpful. :)
It uses mzscript's internal variables mousex and mousey and a timer to run the check in certain intervals.
It doesn't work "out of the box", but you simply need to modify/specify some settings/variables.
The first thing is, we have two modules. By default, Module1 is displayed. We want Module2 to show up at the same location when we enter Module1. So we set up Module1 to execute a bang on the OnEnter event.
!Show<Module2> is a custom bang which hides Module1, shows Module2 and launches a timer. This timer calls the script which checks the mouse position every n seconds.
Once the mouse leaves the defined area (see below), module visibility returns to default.
Now we set up the !CheckIfMouseOn<Module2> Bang called by the timer, and the coordinates of the area in it.
The rest of the Bang calles the actual Mouse Position Evaluation Routine (MPER (c)) and then the !Hide<Module2> Bang if the mouse has left the specified area.
At last, the following evaluates if the mouse is inside the specified area. If so, the timer is removed, if not, it is restarted and will repeat the whole procedure.
That's it. Hope everything is made clear :)
Note #1: Now you ask, this is nothing but a complicately set up Hotspot?! - Well yes, indeed. But i used to have some problems with Hotspots sometimes not noticing the mouse leaving. So i created this one as a "safe" method ;)
Note #2: This one is dedicated to my girlfriend :P
It uses mzscript's internal variables mousex and mousey and a timer to run the check in certain intervals.
It doesn't work "out of the box", but you simply need to modify/specify some settings/variables.
The first thing is, we have two modules. By default, Module1 is displayed. We want Module2 to show up at the same location when we enter Module1. So we set up Module1 to execute a bang on the OnEnter event.
<Module1>OnEnter !Show<Module2>
!Show<Module2> is a custom bang which hides Module1, shows Module2 and launches a timer. This timer calls the script which checks the mouse position every n seconds.
Once the mouse leaves the defined area (see below), module visibility returns to default.
*Script bang !Show<Module2>
*Script exec !<Module1>Hide
*Script exec !<Module2>Show
*Script exec !TimerAdd ATimer <n> !CheckIfMouseOn<Module2>
*Script exec !TimerStart ATimer
*Script ~bang
*Script bang !Hide<Module2>
*Script exec !<Module2>Hide
*Script exec !<Module1>Show
*Script ~bang
*Script exec !<Module1>Hide
*Script exec !<Module2>Show
*Script exec !TimerAdd ATimer <n> !CheckIfMouseOn<Module2>
*Script exec !TimerStart ATimer
*Script ~bang
*Script bang !Hide<Module2>
*Script exec !<Module2>Hide
*Script exec !<Module1>Show
*Script ~bang
Now we set up the !CheckIfMouseOn<Module2> Bang called by the timer, and the coordinates of the area in it.
The rest of the Bang calles the actual Mouse Position Evaluation Routine (MPER (c)) and then the !Hide<Module2> Bang if the mouse has left the specified area.
*Script bang !CheckIfMouseOn<Module2>
*Script exec !execute [!varset x1 $<Module2>X$][!varset x2 $<Module2>X+<Module2>Width$][!varset y1 $<Module2>Y$][!varset y2 $<Module2>Y+<Module2>Height$]
*Script exec !CheckIfMouseOnArea
*Script gotoif ("%{NotOnArea}" = "true") l_NotOnArea
*Script exit
*Script label l_NotOnArea
*Script exec !Hide<Module2>
*Script ~bang
*Script exec !execute [!varset x1 $<Module2>X$][!varset x2 $<Module2>X+<Module2>Width$][!varset y1 $<Module2>Y$][!varset y2 $<Module2>Y+<Module2>Height$]
*Script exec !CheckIfMouseOnArea
*Script gotoif ("%{NotOnArea}" = "true") l_NotOnArea
*Script exit
*Script label l_NotOnArea
*Script exec !Hide<Module2>
*Script ~bang
At last, the following evaluates if the mouse is inside the specified area. If so, the timer is removed, if not, it is restarted and will repeat the whole procedure.
*Script bang !CheckIfMouseOnArea
*Script exec !execute [!varint x1][!varint x2][!varint y1][!varint y2]
*Script gotoif ("%{mousex}" < "%{x1}") l_NotOnArea
*Script gotoif ("%{mousex}" >= "%{x2}") l_NotOnArea
*Script gotoif ("%{mousey}" < "%{y1}") l_NotOnArea
*Script gotoif ("%{mousey}" >= "%{y2}") l_NotOnArea
*Script exec !execute [!TimerKill ATimer][!TimerStart ATimer]
*Script exec !varset NotOnArea false
*Script exit
*Script label l_NotOnArea
*Script exec !varset NotOnArea true
*Script exec !TimerRemove ATimer
*Script ~bang
*Script exec !execute [!varint x1][!varint x2][!varint y1][!varint y2]
*Script gotoif ("%{mousex}" < "%{x1}") l_NotOnArea
*Script gotoif ("%{mousex}" >= "%{x2}") l_NotOnArea
*Script gotoif ("%{mousey}" < "%{y1}") l_NotOnArea
*Script gotoif ("%{mousey}" >= "%{y2}") l_NotOnArea
*Script exec !execute [!TimerKill ATimer][!TimerStart ATimer]
*Script exec !varset NotOnArea false
*Script exit
*Script label l_NotOnArea
*Script exec !varset NotOnArea true
*Script exec !TimerRemove ATimer
*Script ~bang
That's it. Hope everything is made clear :)
Note #1: Now you ask, this is nothing but a complicately set up Hotspot?! - Well yes, indeed. But i used to have some problems with Hotspots sometimes not noticing the mouse leaving. So i created this one as a "safe" method ;)
Note #2: This one is dedicated to my girlfriend :P