help needed: trying to compact some code (and its not working)
Gotten back to workin on an old addon of mine. FinalFantasylization. Plays music based on where you are and what youre doing. (Still only works in WotLK atm, will worry about that later). Been trying to compact the zone detection section.
Here's the github for all the current code: (this bit works fine in WotLK) https://github.com/Darken5/FinalFant...Route-to-3.3.0 Heres the code im workin on compacting: (this works) http://pastebin.com/XCZb6ehw Snippet: Lua Code:
Heres the compacted code: (this doesn't work) http://pastebin.com/XpbSgvZL Snippet: Lua Code:
problem i'm having is the compacted code keeps changing the song played. Example, using the above snippet, it'll play "Sunstrider Isle" then about 2 seconds later plays "Eversong Woods" (which is further down the list), and then back again. If not in a subzone detected by FFz, it'll just repeat the music set for the zone. i've also tried: (my 1st attempt) Lua Code:
Any help in understanding why the compacted code doesn't work would be VERY much appreciated. |
If you're for support on an addon that's going to run on private servers, we won't be able to offer it as it violates the site rules and Blizzard's EULA.
Quote:
Quote:
|
I'm trying to get it up to date with Legion. There is a "lot" of work to do. The code is old code, most still from 2009. Just trying to compact the zone detection to make it a bit simpler to work with for future development. Legion 7.0.3 broke the playMusic() function so there was no point in trying to update it then.
libBabble-Zones is depreciated, gonna move to mapID(). Would love to finally use ACE3.0, tho I'd probably be better off rewriting the whole thing from scratch if that's the case. Gonna have to swap over to the mount Journal to detect what mount I'm riding. |
I use the HereBeDragons library for map detection in Archy and NPCScan. It's also used by TomTom, GatherMate, and a number of other AddOns.
|
Quote:
Edit: yea, deffinately too much. not looking to incorporate coordinates or anything like that. just lookin to check if a player is in certain zones or subzones (either like above, or in some kind of table) and play music set to that area. It has a song for each Zone, and a song for certain SubZones. As far as i know, libBabble-SubZone is still getting updates (only use it for localization purposes, as i don't think there is a SubZone ID list anywhere) Thank you though. it did give me a better idea of how mapID() works. |
By George I think i figured it out.
Faction Dependant Towns/Areas: Lua Code:
Neutral Towns/Areas: Lua Code:
Full Zones (at bottom of list): Lua Code:
whole lot less code to worry about now for the future |
I would honestly build a generic table and two faction-specific override tables to store the references between each song file and MapIDs. You would have the addon detect when you change zones, look in the appropriate faction-specific table for the song to play, falling back to the generic table if none are found, and play the song if it is different than the one already playing.
|
I don't really understand how tables work yet. How would I go about doing that? That sounds awesome.
Edit: song files are stored in separate dependent add-ons called soundpacks that can be switched between with a slash command. Using above code as example "FinalFantasylization_EasternKingdomsAlteracMountains()" is what calls the function in the soundpack that plays the song for Alterac Mountains. |
|
Here's code for the main part of the addon that I whipped up. It uses metatables to handle falling back to a generic song table. Be sure the file containing this code loads first in your ToC.
Lua Code:
In your sound packs placed in other Lua files in the same addon, you can register songs like this. Lua Code:
PS: The first return of UnitFactionGroup() is locale-independant, so it doesn't need to be localized. |
Sorry to interrupt, but I just got a quick question to SDPhantom.
After watching some tutorials about metatable, I got the generic concept of it in Lua. However, I am still struggling to understand how and why metatable is used in your example. So, if you don't mind, could I please get some further explanation regarding this? Thank you. |
To SDPhantom: thank you for the write up, I'll check it out a bit more after I get home.
To Layback_: mind sharing the metatable guides? That would be awesome. |
Hi Darken5,
Here are two video links that I personally find useful. https://www.youtube.com/watch?v=CYxMfVy5W00 This one seems to explain the brief concept of metatable in Lua.. https://www.youtube.com/watch?v=22QTG81kJaQ After I posted a previous reply, I've done some further research, because I was unsure of metamethod and this video explains on how you could implement them. Now I think I got why SDPhantom had used metatable in his example :) https://www.lua.org/pil/13.html This is just a link to official lua documentation page of metatable section. Hope this helps! |
Quote:
Metatables offer a way to control how tables respond to different operations. To implement a fallback table to another, I assigned it to the index operation by setting it to __index in its metatable. This operation is referred to when Lua looks for an entry in a table and doesn't find anything. If another table is assigned to __index in the metatable, it looks through that in addition to the original table. If you're interested in the official documentation, here's the link. Lua 5.1 Reference Manual Section 2.8 |
Thank you both so much. This is far beyond what I expected. And the code is amazing now that I actually understand what it's Doing.
|
All times are GMT -6. The time now is 01:19 AM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI