kevenvz Posted September 20, 2013 Posted September 20, 2013 Hey i got this code and it wont return the function. Can anybody help? addEventHandler("onClientClick",root, function(button,state) if (button ~= "left") or (state ~= "down") then return end for _,dxElement in pairs(getElementsByType("dxButton")) do local posX,posY = getCursorPosition() local screenWidth,screenHeight = guiGetScreenSize() local mouseX, mouseY = posX * screenWidth, posY * screenHeight if (mouseX >= AbsoluteToRelativX(getElementData(dxElement,"x"))) and (mouseX <= AbsoluteToRelativX(getElementData(dxElement,"x") + getElementData(dxElement,"width"))) and (mouseY >= AbsoluteToRelativX(getElementData(dxElement,"y"))) and (mouseY <= AbsoluteToRelativX(getElementData(dxElement,"y") + getElementData(dxElement,"height"))) then return getElementData(dxElement,"handledFunction") end end end) setElementData(dxElement,"handledFunction",testFunction) function testFunction() outputDebugString("TEST DONE!") end
Castillo Posted September 20, 2013 Posted September 20, 2013 You are defining the function after you set the element data. San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
kevenvz Posted September 20, 2013 Author Posted September 20, 2013 Its 2 different codes, actually it is: statsButton = dxCreateButton(10, 910, 130, 130, "files/stats.png", "Stats", tocolor(255, 255, 255, 255), 1, "bankgothic", "center", "bottom", false, true, testFunction, botBar) I am working on my own dx library but it sets all the elements data then it renders it and then it should trigger which it won't! Edit: I can give yoy the source but please dont leak it! I will release it soon so
Moderators IIYAMA Posted September 21, 2013 Moderators Posted September 21, 2013 you are returning to a handler function, with that you are also breaking your main loop. Do you want to improve your Lua programming skills and make less mistakes? Start with Lua Language Server! Useful functions 3x Spoiler checkPassiveTimer getScreenStartPositionFromBox getPedGender Tutorials 4x Spoiler Scaling DX Events Attach an addEventHandler on a group of elements Debugging
kevenvz Posted September 22, 2013 Author Posted September 22, 2013 So any solution of making this? I would love to have this!
Moderators IIYAMA Posted September 22, 2013 Moderators Posted September 22, 2013 well I am not going to find all code mistakes... But: testFunction(getElementData(dxElement,"handledFunction")) break instead of: return getElementData(dxElement,"handledFunction") Do you want to improve your Lua programming skills and make less mistakes? Start with Lua Language Server! Useful functions 3x Spoiler checkPassiveTimer getScreenStartPositionFromBox getPedGender Tutorials 4x Spoiler Scaling DX Events Attach an addEventHandler on a group of elements Debugging
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