Thread Tools Display Modes
10-30-08, 07:18 PM   #1
Seglberg
An Aku'mai Servant
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 33
Pause When World Map is Visible

Is there someway to pause the execution of my lua script?

I need to have my code pause execution when the World Map is open then resume once it's shut. I'm finding this a more difficult task that I thought it would be since the CLOSE_WORLD_MAP event does not work.
  Reply With Quote
10-30-08, 07:49 PM   #2
Taffu
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Jan 2006
Posts: 149
What exactly are you trying to do? Some details might help with figuring out and alternate way to do this (or a workaround).
  Reply With Quote
10-30-08, 08:05 PM   #3
Seglberg
An Aku'mai Servant
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 33
When a function in my addon executes, it changes the world map to the current map the player is on then grabs the continent code from that map. The problem with this is if the player is looking at the map when they change zones the map switches back to the map of their location.

I wanted to make it so if they were in the world map the function would pause then when they exit the world map it would resume the function so the player won't have the map changing on them while they are looking at it.

Also if there is a way to grab the Continent Code without having to use the World Map that would solve my problem too.

Last edited by Seglberg : 10-30-08 at 08:30 PM.
  Reply With Quote
10-31-08, 08:45 AM   #4
Taffu
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Jan 2006
Posts: 149
Well, you can use WorldMapFrame:IsShown() to determine if the WorldMap is currently shown, however conflicting AddOns might make this problematic (ie. Carbonite).

You can also use the work around explained in WoWWiki using the WORLD_MAP_UPDATE event:

Code:
local Map_Changed = false;

function MyAddon_OnEvent()
 if ( (event == "WORLD_MAP_UPDATE") and WorldMapFrame:IsVisible() ) then
  Map_Changed = true;
 end
end

function MyAddon_OnUpdate()
 if ( (Map_Changed) and not WorldMapFrame:IsVisible() ) then
  ...do this...
  Map_Changed = false;
 end
end
  Reply With Quote
10-31-08, 02:39 PM   #5
Seglberg
An Aku'mai Servant
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 33
Yes I saw that however I am using Ace3 and cannot figure how to get an OnUpdate function working.

If you want to look at the source code, its the addon RepWatch

Last edited by Seglberg : 10-31-08 at 02:41 PM.
  Reply With Quote
11-02-08, 12:32 AM   #6
Seglberg
An Aku'mai Servant
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 33
Can anyone help me out a bit? New at making addons and so I'm not exactly sure how to do an OnUpdate function using Ace3, or something equivilent.

I know how to run the code when WORLD_MAP_UPDATE fires but idk exactly how to (or exactly 100% was it is) set up the OnUpdate() function.

Any help would be appriciated, would like to get this done before Wrath releases because it's really annoying to have the map switch when looking at it. Thanks.
  Reply With Quote
11-02-08, 04:30 PM   #7
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
It should be done the same way you would do it if you weren't using any libraries. frame:SetScript("OnUpdate", function() ... end)
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
11-02-08, 09:21 PM   #8
Seglberg
An Aku'mai Servant
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 33
Okay I tried that already but I probably did it wrong :P

Ill try it when I get a chance, thanks.

Last edited by Seglberg : 11-02-08 at 10:01 PM.
  Reply With Quote
11-02-08, 10:04 PM   #9
Seglberg
An Aku'mai Servant
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 33
Okay so wait do I do:

WorldMapFrame:SetScript("OnUpdate", MapUpdate)?

If I do that the OnUpdate runs while the map is open but once it shuts it doesnt fire so I can't use that code posted above. It doesn't fire again so that it can see that WorldMapFrame isnt visible and so it must of closed.


Here is what I have for my code:

Code:
WorldMapFrame:SetScript("OnUpdate", MapUpdate)

local Map_Changed = false;

-------------------------------------
function RepWatch:WORLD_MAP_UPDATE()
-------------------------------------

	if WorldMapFrame:IsVisible() then
		Map_Changed = true
	end	
end

-------------------------------------
function MapUpdate()
-------------------------------------
	if ( (Map_Changed) and not WorldMapFrame:IsVisible() ) then
		Map_Changed = false;
		RepWatch:Print("Map Closed")
	end
end

Last edited by Seglberg : 11-02-08 at 10:07 PM.
  Reply With Quote
11-03-08, 01:45 AM   #10
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
Your OnUpdate handler should be at the bottom of your code. MapUpdate doesn't exist yet where you have it.

Also, since you assigned the OnUpdate to the WorldMapFrame, it will only run when shown and will stop when :Hide() is called on the map frame. If you want the code to run when the map is closed and not when the map is open, you need to assign it to a different frame (can be invisible). You can then have that frame show/hide based on whether the map is open or not, making your OnUpdate run/pause.
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
11-03-08, 01:30 PM   #11
Taffu
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Jan 2006
Posts: 149
What Seerah said, it should look like this:

Code:
local Map_Changed = false;

-------------------------------------
function RepWatch:WORLD_MAP_UPDATE()
-------------------------------------
	if WorldMapFrame:IsVisible() then
		Map_Changed = true
	end	
end

-------------------------------------
local function MapUpdate()
-------------------------------------
	if ( (Map_Changed) and not WorldMapFrame:IsVisible() ) then
		Map_Changed = false;
		RepWatch:Print("Map Closed")
	end
end

WorldMapFrame:SetScript("OnUpdate", MapUpdate)
I'd make the MapUpdate function local instead of global

To avoid the issue that Seerah mentioned with the WorldMapFrame OnUpdate script, I would suggest definately making an independent frame to run the script on. Just add...

Code:
local MapChangedFrame = CreateFrame("Frame")
...prior to your code snippet above and should should be all set. Associate the OnUpdate script to that frame and you don't have to worry about the WorldMapFrame anymore.
  Reply With Quote
11-03-08, 04:00 PM   #12
Seglberg
An Aku'mai Servant
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 33
Wow Thanks I got it working perfectly!

You guys are so helpful here!
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Pause When World Map is Visible

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off