Thanks for testing it. Good to hear that it works with players - it took jumping through a lot of hoops to test it with bots, and obviously in a normal game I don't want bots to show up on the player list nor be ignorable.
I'm not sure how much I'll expand it at this point, I guess it depends on how badly people want built-in offline list addition/removal, or what other similar features I or others can think of - chat size and timeout were obvious, because I found both to be really, really annoying at default while testing the mod myself.
The chat size still kind of needs an adjustment to the line number calculation-- there are 10 history lines at font size 18, but if you make it smaller, there are more than 10 and the auto-width adjustment only adjusts to the last 10 lines which occasionally makes the window narrower than the earliest two or three lines of visible text.
And another question- how do know what options are available for a function. For instance, in the xp mod, you use OnHeroChange(unit) - and also function create(parent) - how do you know what you can use? I'm referring to whatever appears between ( ). Is this defined somewhere? That would fill in a big blank in my understanding. Thx.
They're defined right there, in the function definition itself. When you define a function, you also define the names of its parameters. I could call them 'bleeg' and 'flarn' if I wanted to, and they'll still represent the first two parameters passed to any call of that function, and it's the number of them that's important, not their names. This:
Code: c++
- local prevOnHeroChange = OnHeroChange
- function OnHeroChange(meep)
- prevOnHeroChange(meep)
- if meep then
- --do stuff with meep, which is the unit
- end
- end
..is perfectly valid, and neither the previous version of OnHeroChange nor any other mods that hook my version of the function know or care what I named the parameter variable, only its contents. I could even add an extra parameter, although in this case, that would do nothing since the function is only being called with one parameter. Lua is really flexible when it comes to things like this.
You can remove parameters too, which is essentially what happens when OnHeroChange is called in observer mode or with a dead demigod (the parameter passed to it, normally the user unit object for that demigod, is nil, or non-existent-- which is what caused problems for the original mod), but there's pretty much never actually a reason to remove parameters from the function definition itself, especially a function that multiple mods may hook (as that would break all mods that rely on those parameters).
As mentioned, the number of parameters passed to the function in any/all of its calls determine how many it needs in its definition. Or, more accurately, the reverse, but when you're hooking an existing function, that's how you know for certain what's being passed to it and how many parameters it uses. In the case of OnHeroChange, it's initially confusing, because the function is never called directly in HUD_xp.lua. It's added as a callback function via /lua/ui/game/InGameUI.lua, and called by SetFocusArmyHero on line 125 of that file with one parameter - the unit passed to that function by UpdateForNewArmy at line 27, which you can see getting (or failing to get) a handle to the hero unit.
and one other thought about the mod you are working on. Is there any way you can create some sort of toggle that might capture the in game chat to a txt file? Even without a toggle, something like that could be fun.
I'm not sure. The game only allows lua to write to the preferences file (which has limitations) and the log. I could make a UI-side mod that outputs all chat messages to the log fairly easily, and gives them a unique tag so that they're easy to search/filter for, but you'd still have to run with the log enabled, and find some program to pick them out of all the other spam.
In fact, it's so easy, it took about 3 minutes: http://pastebin.com/bLnFAHGh
Not tested, but it's pretty simple. I just hooked ReceiveChat, aped the first part of its sender formatting/localization, prepend [CHAT] and/or *ignored* to the message, and dump it to the log. No on/off switch, but it's probably not something most people will use / know how to use anyway, so it's best in a standalone mini-mod. To be clear, this only logs chat received in the UI, and has no more access to enemy team chat than the normal UI.