Anderl Posted July 5, 2012 Posted July 5, 2012 Hi guys. I was making a script when I got a problem: I need to add a handler to a method, and it's the only way to use the function, with methods. I don't know how would I add it cuz I get error and I can't do: function( ) self:__window( ) end as function cuz I'll need to remove handler later. Can somebody help? Note: If you don't know, don't answer! "[...] If you don’t love it, if you’re not having fun doing it, you don’t really love it, you’re going to give up." - Steve Jobs, 2007
Anderl Posted July 7, 2012 Author Posted July 7, 2012 Damn, no one knows? "[...] If you don’t love it, if you’re not having fun doing it, you don’t really love it, you’re going to give up." - Steve Jobs, 2007
robhol Posted July 7, 2012 Posted July 7, 2012 I can't really say that I understand what the problem is. "I need to add a handler to a method, and it's the only way to use the function, with methods." doesn't really tell us what's wrong, why it's wrong, or what you're trying to do. Do NOT PM ME for help unless invited. - New MTA Script Editor Scripting help "etiquette": understandable language, relevant code (ALL code if unsure), [Lua] tags, error messages with line numbers. Super simple stuff.
Anderl Posted July 7, 2012 Author Posted July 7, 2012 lolz, I want to add handler to a method like: addEventHandler( 'onClientRender', root, self:__window ); But it gives error like: something.. in function arguments '('. Something like that. "[...] If you don’t love it, if you’re not having fun doing it, you don’t really love it, you’re going to give up." - Steve Jobs, 2007
robhol Posted July 7, 2012 Posted July 7, 2012 I can't pretend to know what, exactly, that self thing means. When coding OOP, I prefer it to be... err, proper OOP? Looks like it's causing some problems though. For starters, how about a proxy function that calls the method? Assigning that method to a local variable and using that, on the off chance that the self: stuff is causing issues with the addEventHandler call? Do NOT PM ME for help unless invited. - New MTA Script Editor Scripting help "etiquette": understandable language, relevant code (ALL code if unsure), [Lua] tags, error messages with line numbers. Super simple stuff.
Jaysds1 Posted July 8, 2012 Posted July 8, 2012 debugscript 3 and show what's wrong Actually post a screenshot of the debug error(if any) My in-game name: Jaysds1 Retired CMG Scripter World Of Tanks GameMode (Open-Source): https://github.com/Jaysds1/mtasa-wot-gamemode Online GUI-Editor (WIP): https://forum.mtasa.com/topic/47678-online-gui-editor/
robhol Posted July 8, 2012 Posted July 8, 2012 He did already post an error, but a verbatim copy would be nice. Anyway, Lua is a bad language for OOP (half-assed and less-than-intuitive implementation) and MTA's API doesn't really go well with it either. How about sticking to procedural-style programming? Do NOT PM ME for help unless invited. - New MTA Script Editor Scripting help "etiquette": understandable language, relevant code (ALL code if unsure), [Lua] tags, error messages with line numbers. Super simple stuff.
Kenix Posted July 8, 2012 Posted July 8, 2012 lolz, I want to add handler to a method like: addEventHandler( 'onClientRender', root, self:__window ); But it gives error like: something.. in function arguments '('. Something like that. it's wrong, because you call method, so correct addEventHandler( 'onClientRender', root, self.__window ); here you use function, instead of call method. http://vk.com/the_kenix Вопросы задавайте на форуме, не пишите мне в личку. Please don't pm me.
Anderl Posted July 8, 2012 Author Posted July 8, 2012 But you can't call self in the function __window anymore. Let me show you the code in Skype to you see how it should be. "[...] If you don’t love it, if you’re not having fun doing it, you don’t really love it, you’re going to give up." - Steve Jobs, 2007
50p Posted July 8, 2012 Posted July 8, 2012 Seems like you're trying to make a lib with DX functions? Why don't you have a "global" onClientRender in your class for all its objects? local renderObjects = { }; table.insert( renderObjects, yourObject ); -- when new object is created, add it to the list of objects to render addEventHandler( "onClientRender", root, function( ) for k, v in pairs( renderObjects ) do if v:Visible() then -- i guess you have a method to check if object is visible v:__window( ); end end end ); - MTA Script Editor - Ask your scripting questions properly, please. - 50p's public resources - Meta.xml - what is it for? How is it possible LOL
Anderl Posted July 8, 2012 Author Posted July 8, 2012 Seems like you're trying to make a lib with DX functions? Why don't you have a "global" onClientRender in your class for all its objects? local renderObjects = { }; table.insert( renderObjects, yourObject ); -- when new object is created, add it to the list of objects to render addEventHandler( "onClientRender", root, function( ) for k, v in pairs( renderObjects ) do if v:Visible() then -- i guess you have a method to check if object is visible v:__window( ); end end end ); lolz, so much time thinking and didn't remember that way Thank you. And yes, I'm making a lib with DX functions. "[...] If you don’t love it, if you’re not having fun doing it, you don’t really love it, you’re going to give up." - Steve Jobs, 2007
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now