Thread Tools Display Modes
07/02/15, 08:35 AM   #1
ZunaSW
Join Date: Mar 2014
Posts: 37
Display image depending on the zone

Hello,

I'm now trying some other things, mainly I want to display an image depending on the zone the player is.
My idea is this:
If for example the player is in Eastmarch zone, Image1 will be displayed as a key is pressed. If then the player changes to Stonefalls zone, Image2 will be displayed as the same key is pressed.

I got no problems with the keybindings, but I'm having problems displaying the different images. For now, when I press the key, I get a 1024x1024 blank image, as I stated here:

Code:
local wm = GetWindowManager()
local MainImage = wm:CreateTopLevelWindow(nil)
MainImage:SetDimensions(1024,1024)
MainImage:SetAnchor(CENTER,GuiRoot,CENTER,0,0)
MainImage0 = wm:CreateControl(nil, MainImage, CT_TEXTURE)
MainImage0:SetAnchorFill(MainImage)
MainImage0:SetHidden(true)
I got this code from other of my addons, I'm no expert, so that might be wrong :/ But for now, works.

Now I got the keybinding code:

Code:
function IM.OnKeyDown()
	MainImage0:SetHidden(false)
end

function IM.OnKeyUp()
	MainImage0:SetHidden(true)
end
That works perfectly.

And here is the code that I think it is wrong, even when I don't get any errors in game:

Code:
function IMOnZoneChanged(eventCode, zoneName, subZoneName, newSubzone)
	if zoneName == "Eastmarch" then
		MainImage0:SetTexture("IM/textures/Image1.dds")
	end
	if zoneName == "Stonefalls" then
		MainImage0:SetTexture("IM/textures/Image2.dds")
	end
end

EVENT_MANAGER:RegisterForEvent(IM.name, EVENT_ZONE_CHANGED, IMOnZoneChanged)
For now, as I said, this last part of the code seems to not work, or at least do what I want it to do. I press the key and get a blank image, instead of the images I stated in the last code.

Any ideas on how to make this work? Maybe I'm using the wrong event, I'm not sure, as I said, I'm no expert.

Thank you.
  Reply With Quote
07/02/15, 08:56 AM   #2
merlight
AddOn Author - Click to view addons
Join Date: Jul 2014
Posts: 671
If you added/changed any .dds files while the game was running, you might need to restart the client. It caches textures (and their absence as well).
  Reply With Quote
07/02/15, 09:11 AM   #3
ZunaSW
Join Date: Mar 2014
Posts: 37
Hm, nothing, didn't work :c

Must be something from the code.
  Reply With Quote
07/02/15, 11:07 AM   #4
votan
 
votan's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2014
Posts: 577
Originally Posted by ZunaSW View Post
Hm, nothing, didn't work :c

Must be something from the code.
hmm, the first zone after loading does not trigger a "change".

You could try to call your zone change function like this in EVENT_PLAYER_ACTIVATED:
Code:
IMOnZoneChanged(0, GetUnitZone("player"))
  Reply With Quote
07/02/15, 11:23 AM   #5
ZunaSW
Join Date: Mar 2014
Posts: 37
Hm, nothing, doesn't seem to work, I'm using this code, might be wrong though:

Code:
function IMOnZoneChanged(0, GetUnitZone("player"))
	if zoneName == "Eastmarch" then
		MainImage0:SetTexture("IM/textures/Image1.dds")
	end
	if zoneName == "Stonefalls" then
		MainImage0:SetTexture("IM/textures/Image2.dds")
	end
end
And I'm getting this error:

Code:
user:/AddOns/IM/IM.lua:30: <name> or "..." expected near '0
I might have done something wrong with the event. I'm pretty new on this, so I don't really know :S
  Reply With Quote
07/02/15, 11:36 AM   #6
votan
 
votan's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2014
Posts: 577
Originally Posted by ZunaSW View Post
Hm, nothing, doesn't seem to work, I'm using this code, might be wrong though:

Code:
function IMOnZoneChanged(0, GetUnitZone("player"))
	if zoneName == "Eastmarch" then
		MainImage0:SetTexture("IM/textures/Image1.dds")
	end
	if zoneName == "Stonefalls" then
		MainImage0:SetTexture("IM/textures/Image2.dds")
	end
end
And I'm getting this error:

Code:
user:/AddOns/IM/IM.lua:30: <name> or "..." expected near '0
I might have done something wrong with the event. I'm pretty new on this, so I don't really know :S
I was not precise (or lazy?) Calling, not declaring.
Lua Code:
  1. local function IMOnZoneChanged(eventCode, zoneName, subZoneName, newSubzone)
  2.     if zoneName == "Eastmarch" then
  3.         MainImage0:SetTexture("IM/textures/Image1.dds")
  4.     end
  5.     if zoneName == "Stonefalls" then
  6.         MainImage0:SetTexture("IM/textures/Image2.dds")
  7.     end
  8. end
  9.  
  10. local function PlayerActivated()
  11.   EVENT_MANAGER:UnregisterForEvent(IM.name, EVENT_PLAYER_ACTIVATED)
  12.   IMOnZoneChanged(0, GetUnitZone("player"))
  13. end
  14.  
  15. EVENT_MANAGER:RegisterForEvent(IM.name, EVENT_ZONE_CHANGED, IMOnZoneChanged)
  16.  
  17. EVENT_MANAGER:RegisterForEvent(IM.name, EVENT_PLAYER_ACTIVATED, PlayerActivated)
^^ Typed without testing

About names from API you should read this.
  Reply With Quote
07/02/15, 11:57 AM   #7
ZunaSW
Join Date: Mar 2014
Posts: 37
Ohhh, I think I get it.
I'm checking that link you put there, it is useful, I think I'm getting things, slowly, but I am ^^.

I tried this code you put there, but I'm getting another error D:

Code:
user:/AddOns/IM/IM.lua:35: attempt to index a nil value
stack traceback:
	user:/AddOns/IM/IM.lua:35: in function '(main chunk)'
I never get what this error means, and I've got it in many addons I tried to do. The line this error reffers to is:

Code:
EVENT_MANAGER:RegisterForEvent(IM.name, EVENT_ZONE_CHANGED, IMOnZoneChanged)
Been checking, but I don't see what is wrong there. Trying hard on making my first well done addon.

Sorry for all these questions x'D
  Reply With Quote
07/02/15, 12:15 PM   #8
votan
 
votan's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2014
Posts: 577
Originally Posted by ZunaSW View Post
Been checking, but I don't see what is wrong there. Trying hard on making my first well done addon.

Sorry for all these questions x'D
Sure, no problem
If it is you first: Welcome!

The order of declaration is important in Lua. Is IM declared before line 35?
If the error persists, post the whole source.
  Reply With Quote
07/02/15, 12:35 PM   #9
ZunaSW
Join Date: Mar 2014
Posts: 37
Oh great! It works now! Now when I press the key while in Eastmarch, it shows Image1, when I press the key while in Stonefalls it shows Image2. Though, I think I'm not done yet, as if I travel from Stonefalls to Eastmarch and press the key again, it shows still Image2, when it should show Image1. I imagine this will be some kind of update event, right? Works perfectly if after travelling I make reloadui.

I think I should use EVENT_ZONE_UPDATE, but I'm not sure how to make this :S

Any ideas?

Many thanks for the help, really
  Reply With Quote
07/02/15, 12:44 PM   #10
votan
 
votan's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2014
Posts: 577
Originally Posted by ZunaSW View Post
Oh great! It works now! Now when I press the key while in Eastmarch, it shows Image1, when I press the key while in Stonefalls it shows Image2. Though, I think I'm not done yet, as if I travel from Stonefalls to Eastmarch and press the key again, it shows still Image2, when it should show Image1. I imagine this will be some kind of update event, right? Works perfectly if after travelling I make reloadui.

I think I should use EVENT_ZONE_UPDATE, but I'm not sure how to make this :S

Any ideas?

Many thanks for the help, really
Ah, yes. Traveling is player deactivate and activate rather than zone change. I guess you just need to omit the unregister of EVENT_PLAYER_ACTIVATED
  Reply With Quote
07/02/15, 12:54 PM   #11
ZunaSW
Join Date: Mar 2014
Posts: 37
Omg, it works!!!
Now it works perfectly! Thank you for your help, really I hope to finish this addon and do it good! ^^
  Reply With Quote
07/02/15, 01:20 PM   #12
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 1,567
Welcome to EsoUI!

Just wanted to say that if you want to make this more robust in the future you should not depend on zoneName to determine which zone you are in, because it will be a different string for different client languages.
There is a small library that votan and I made which makes finding out the zone independent of the client language a bit easier amongst other things.
You might want to look into that if you plan to share your addon with others that are not playing in the same language as yourself.
  Reply With Quote
07/02/15, 05:51 PM   #13
ZunaSW
Join Date: Mar 2014
Posts: 37
Thanks Sirinsidiator : P

And yes, that is true, didn't think about that, hrm. I'll check the link you put there, and see what can I do!
Thank you!
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » Display image depending on the zone

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