Thread Tools Display Modes
01/03/17, 08:20 PM   #1
Bobby Blue
Join Date: Dec 2016
Posts: 5
Overriding default functions

Hi all,

I'm just trying to write a simple addon that inserts timestamps at the start of every chat message (I know, that's been done before, but I'm just trying to learn, so I thought I'd start with something small).

At this point, I'm trying to override SharedChatContainer:OnChatEvent:
Lua Code:
  1. function SharedChatContainer:OnChatEvent(event, formattedEvent, category)
  2.     formattedEvent = GetTimestamp() .. formattedEvent           -- My code
  3.     for i=1, #self.windows do
  4.         if IsChatContainerTabCategoryEnabled(self.id, i, category) then
  5.             self:AddEventMessageToWindow(self.windows[i], formattedEvent, category)
  6.         end
  7.     end
  8. end

But that doesn't seem to work for some reason. The error I am getting is 'expecting function instead of nil', so I've already understood that the function is unable to access the Timestamps table. Why? Is there some way to work around this?

And yes, I do want to call the GetTimestamp() function, because I am formatting the result of ZO_FormatClockTime() before using it.

Thanks for your help and happy new year

Last edited by Bobby Blue : 01/03/17 at 09:22 PM.
  Reply With Quote
01/03/17, 08:37 PM   #2
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,966
The function names are case sensitive:

Lua Code:
  1. * GetTimeStamp()
  2. ** _Returns:_ *id64* _timestamp_

You need to write "Stamp" with a capital S then.

Edit
ESOUIDocumentationP12.txt

Last edited by Baertram : 01/03/17 at 08:42 PM.
  Reply With Quote
01/03/17, 09:10 PM   #3
Bobby Blue
Join Date: Dec 2016
Posts: 5
Thanks, but I've defined my own GetTimestamp() function, which needs to be in the Timestamps table because I am also loading some saved variables in there.

Lua Code:
  1. function Timestamps.GetTimestamp()
  2.     if Timestamps.Vars.TimeUseChannelColour then
  3.         ...
  4.     end
  5. end

Last edited by Bobby Blue : 01/04/17 at 01:17 AM.
  Reply With Quote
01/04/17, 02:16 AM   #4
Ayantir
 
Ayantir's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2014
Posts: 1,019
Plese.. just.. no.
  • It has already being done
  • Your code can't work right there
  • Your code will break other addons potentially
  • Hacking ESOUI Code for 1st addon is not good.. keep after after months of learnings.
  Reply With Quote
01/04/17, 03:17 AM   #5
Bobby Blue
Join Date: Dec 2016
Posts: 5
Originally Posted by Ayantir View Post
Plese.. just.. no.
  • It has already being done
  • Your code can't work right there
  • Your code will break other addons potentially
  • Hacking ESOUI Code for 1st addon is not good.. keep after after months of learnings.
I mean, thanks for the feedback, but I have to say that that wasn't particularly helpful for me as I'm trying to learn about Lua. If you're going to criticise what I am trying to do, I'd appreciate it if you at least explain why so I can learn from it.

I've replied to each of your points in turn:
  • It has already been done, but so far I have not found an addon that does just timestamps, which someone might want if they just want simple timestamps without giving their entire chat a makeover.
  • Why can't my code work right there? That's what I was asking in the first place. What's the reason behind this not being able to work? I mean, if it straight up just doesn't work, I won't do it, but I want to know why so I can get better at Lua.
  • How will it break other addons unless they're doing the exact same thing that I'm trying to do? All I've done is insert a little bit of text in front of the message that's gonna be displayed, all the rest is copy/pasted from the original code.
  • Well I have to start somewhere, and this seemed like a simple enough thing to do. What sort of things should I focus on first, in your opinion?

I'm not trying to be aggressive or obnoxious, I just really want to learn, rather than be brushed off just because I'm new to Lua/coding addons.
  Reply With Quote
01/04/17, 04:06 AM   #6
Ayantir
 
Ayantir's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2014
Posts: 1,019
The addon ChatStamp add a date stamp to the chat message.. but also pchat and maybe other addons..

by looking at ChatStamp code I would like to replace

Lua Code:
  1. function CS.addChatStamp()
  2.     ...
  3.    
  4.     return chattime
  5.        
  6. end

by your Timestamps.GetTimestamp() code which should return the timestamp.



Your code can't work....
okayyyy now it can work because zos rewrited it because of gamepad chat made at last DLC, but for for 2 years, SharedChatContainer was local.



Your code will break other addons potentially ... because it's chat.. and chat is a UI space where all other addons fights each others. If you rewrite a function, consider another addon perhaps rewrite it also. or use it.. Having to deal when your addon can potentially conflicts wth others on your very first addon.. is not a good thing.



Hacking ESOUI Code for 1st addon is not good.. It's like you wanted to learn C by hacking the Linux Kernel before knowing few concepts that you learn after being a C-Guru for years.

Just do something easier.. or do this .. differently ?


It was just advices of an old coder.

ps:

Lua Code:
  1. function SharedChatContainer:OnChatEvent(event, formattedEvent, category)
  2.         formattedEvent = Timestamps.GetTimestamp() .. formattedEvent           -- My code
  3.         for i=1, #self.windows do
  4.             if IsChatContainerTabCategoryEnabled(self.id, i, category) then
  5.                 self:AddEventMessageToWindow(self.windows[i], formattedEvent, category)
  6.             end
  7.         end
  8.     end

Last edited by Ayantir : 01/04/17 at 04:10 AM.
  Reply With Quote
01/04/17, 04:44 AM   #7
Bobby Blue
Join Date: Dec 2016
Posts: 5
Thanks

Had a look at ChatStamp (you were right, pretty much exactly the same as what I'm trying to make), and turns out that what they do is just use LibChat (which I didn't know existed :P) to insert the timestamp.

I think I'll try to finish my addon anyway just for my personal satisfaction, but if there's already an addon that does the exact same thing I may as well just not upload it. Thanks for your help.
  Reply With Quote
01/04/17, 06:34 AM   #8
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 1,578
Welcome Bobby Blue!
Don't mind Ayantir. He can be a bit harsh sometimes, but he usually has the best intentions.

As he has said, hooking into the chat is not the easiest topic to start, so I suggest you first read the Getting Started guide on the wiki and do the SimpleNotebook tutorial which explains most basics (the lazy bum author hasn't completed it though).
  Reply With Quote
01/05/17, 05:21 AM   #9
Bobby Blue
Join Date: Dec 2016
Posts: 5
Thanks sirinsidiator
No worries, he explained his comments, so I'm quite happy with his response.
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » Overriding default functions


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