Jump to content

return getElementData(source,"function")


kevenvz

Recommended Posts

Posted

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 

Posted

You are defining the function after you set the element data.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

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 :P

  • Moderators
Posted

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 

  Tutorials  4x 

 

  • Moderators
Posted

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 

  Tutorials  4x 

 

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...