UnG//Macaus Posted December 20, 2014 Share Posted December 20, 2014 (edited) I have a problem with my code, everything is working, but the function is executed 2 times when I click on a button. Can someone help me? for id,element_r in ipairs(getElementChildren(dxRootElement)) do for id, element in ipairs(getElementChildren(element_r)) do if getElementData(element,"visible") == true then local g_height = getElementData(element,"height") or 0 local g_width = getElementData(element,"width") or 0 local px, py = dxGetPosition(element) if (button == "left" and state == "up") then if x >= px and x <= (px+g_width) and y >= py and y <= (py + g_height) then triggerEvent("onClientDXClick",element) end end end end end Edited December 31, 2014 by Guest Link to comment
Anubhav Posted December 20, 2014 Share Posted December 20, 2014 Use getTickCount method. When you click just make a variable setting to getTickCount( ) then when you loop before that, check: if getTickCount() - yourVariables > 1000 then -- easier method is a setTimer Link to comment
Dealman Posted December 21, 2014 Share Posted December 21, 2014 Is that the entire function? What if you move this part to the very top of the function? if (button == "left" and state == "up") then Link to comment
UnG//Macaus Posted December 21, 2014 Author Share Posted December 21, 2014 Yes, this is the full function I put this line at the top and still have the same problem Link to comment
MTA Team 0xCiBeR Posted December 21, 2014 MTA Team Share Posted December 21, 2014 That's because your for-loop executes more than one time before you release/press your key. Just break the loop using: break Example: ( Tho i don't know how your script works as you are not showing it entierly ): triggerEvent("onClientDXClick",element) break That will prevent your for-loop to continue looping after you triggered the event Link to comment
UnG//Macaus Posted December 22, 2014 Author Share Posted December 22, 2014 now is not repeating more, except for triggerEvents Example: addEventHandler("onClientDXClick",getRootElement(), function() if (source == button) then triggerServerEvent("test",localPlayer) end end) --server addEvent("test",true) addEventHandler("test",getRootElement(), function() outputChatBox ( "TEST", source, 0, 255, 0) end) Link to comment
Castillo Posted December 22, 2014 Share Posted December 22, 2014 What is the problem? Link to comment
UnG//Macaus Posted December 22, 2014 Author Share Posted December 22, 2014 Only triggerServerEvent is executed 2 times Link to comment
Castillo Posted December 22, 2014 Share Posted December 22, 2014 I guess "onClientDXClick" is being triggered twice then. Link to comment
Anubhav Posted December 22, 2014 Share Posted December 22, 2014 Use getTickCount method. When you click just make a variable setting to getTickCount( ) then when you loop before that, check: if getTickCount() - yourVariables > 1000 then -- easier method is a setTimer This is it, then. Link to comment
UnG//Macaus Posted December 22, 2014 Author Share Posted December 22, 2014 I think you have misunderstood the problem I have now addEventHandler("onClientDXClick",getRootElement(), function() if (source == button) then triggerServerEvent("test",localPlayer) --run 2 times (2 outputChatBox) outputChatBox("test") --run 1 time (1 outputChatBox) end end) Link to comment
Castillo Posted December 22, 2014 Share Posted December 22, 2014 Something else is triggering that event then. Link to comment
3B00DG4MER Posted December 23, 2014 Share Posted December 23, 2014 You can use that function : function isMouseWithinRangeOf(posX, posY, sizeX, sizeY) if isCursorShowing() == false then return false end local cx,cy = getCursorPosition() cx,cy = cx*sW,cy*sH if cx >= posX and cx <= posX+sizeX and cy >= posY and cy <= posY+sizeY then return true,cx,cy else return false end end Link to comment
UnG//Macaus Posted December 23, 2014 Author Share Posted December 23, 2014 As i Know , there is nothing that is triggering the event, does someone have a idea or solution how to solve this problem ? 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