DarkLink Posted July 15, 2012 Share Posted July 15, 2012 I guess this doesnt work on LUA ? Because on my code the part of the removeEventHandler is not working... I have no errors on the clientscript .. Code: addEventHandler( "onClientMouseEnter", small, function() addEventHandler("onClientRender", getRootElement(), function() textAmmo("7 pistol, 12 shotgun, 24 submachine, 30 assault rifles, 5 rifle") end) end, false) addEventHandler("onClientMouseLeave", small, function() removeEventHandler("onClientRender", getRootElement(), function() textAmmo("7 pistol, 12 shotgun, 24 submachine, 30 assault rifles, 5 rifle") end) end, false) And I assure you, that small is defined, and textAmmo is fine.. It works to addEventHandler, but removing the event handler is not working... Would appreciate some help! thanks again! Link to comment
robhol Posted July 15, 2012 Share Posted July 15, 2012 Aside from this looking horrible, you can't remove a function like that. You are defining a new function and passing it to rEH., even if it's exactly the same. Assign it to a local variable, then pass that to rEH. Link to comment
DarkLink Posted July 15, 2012 Author Share Posted July 15, 2012 Aside from this looking horrible, you can't remove a function like that. You are defining a new function and passing it to rEH., even if it's exactly the same.Assign it to a local variable, then pass that to rEH. Horrible? come on, its beautiful ^^ Okay thanks alot, I will try Link to comment
DarkLink Posted July 15, 2012 Author Share Posted July 15, 2012 I cant do it.. Do you mean this ? local textAmmoFunction function textAmmo(text) if(ops and isElement(ops)) then local x,y = guiGetPosition(ops, false) local x1,y1 = guiGetSize (ops, false) dxDrawText ( text, x + 30, y + y1/1.5 ,x + x1, y+y1, tocolor(255,255,255), 1,"default", "left", "top", false, true, true) end end addEventHandler( "onClientMouseEnter", small, function() textAmmoFunction = textAmmo("7 pistol, 12 shotgun, 24 submachine, 30 assault rifles, 5 rifle") addEventHandler("onClientRender", getRootElement(), textAmmoFunction) end, false) addEventHandler("onClientMouseLeave", small, function() removeEventHandler("onClientRender", getRootElement(), textAmmoFunction) end, false) [2012-07-15 17:34:54] WARNING: bp\client_money.lua:60: Bad argument @ 'addEventHandler' [Expected function at argument 3, got nil] [2012-07-15 17:34:55] WARNING: bp\client_money.lua:66: Bad argument @ 'removeEventHandler' [Expected function at argument 3, got nil] Link to comment
DarkLink Posted July 15, 2012 Author Share Posted July 15, 2012 FIXED! thanks alot robhol! didnt know about this... functions as variables For someone with same problem: http://lua-users.org/wiki/LuaTypesTutorial Link to comment
Anderl Posted July 15, 2012 Share Posted July 15, 2012 Nice to see that some people read LUA wikis yet. Link to comment
DarkLink Posted July 15, 2012 Author Share Posted July 15, 2012 Nice to see that some people read LUA wikis yet. Of course! I always try to find my answer somewhere else, but most of times I need to brother someone here on forum eheh Link to comment
robhol Posted July 15, 2012 Share Posted July 15, 2012 Heheh, function-as-variable can come as kind of a surprise if you're not used to it - relatively few languages support this kind of thing. Might actually be my favorite thing about Lua. :3 (Edit: oh, and "horrible" might have been a slight exaggeration. If you indent it sanely, that'll go a long way. ) Link to comment
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