Kilometrs Posted July 11, 2022 Share Posted July 11, 2022 My issue is that for some reason after pressing the corresponding button to call the function, two windows pop up one on another. One of the is responsive (as in - you can press the buttons and they work), the other one can be moved around but the buttons don't lead anywhere. Any ideas why? The code is redesigned older code for the OwlGaming roleplay gamemode (from 2015. if I remember correctly). function showConfirmDelete(id, brand, model, createdby) local w, h = 400,150 ConfirmDeleteWin = dgsCreateWindow((screenwidth-w)/2,(screenheight-h)/2,w,h,"Transportlīdzekļa dzēšana",false, _, _, _, _, _, _, _, true) dgsSetAlpha(vehLib, 0.1) local bty, bth = 0.6, 0.2 labels[8] = dgsCreateLabel(0.0254,0.2072,0.9645,0.1982,"Tu čista gribi dzēst #"..id.."("..brand.." "..model.."), ko veidojis "..createdby.."?",true,ConfirmDeleteWin) dgsLabelSetHorizontalAlign(labels[8],"center",false) labels[9] = dgsCreateLabel(0.0254,0.4054,0.9492,0.2162,"Šī rīcība ir neatgriezeniska!",true,ConfirmDeleteWin) dgsLabelSetHorizontalAlign(labels[9],"center",false) buttons[10] = dgsCreateButton(0.0254,bty,0.4695,bth,"Atcelt",true,ConfirmDeleteWin, _, _, _, _, _, _, 0x99FF0000) dgsSetFont(buttons[10],"clear") addEventHandler("onDgsMouseClick", buttons[10], function() if source == buttons[10] then closeConfirmDelete() end end) buttons[11] = dgsCreateButton(0.5051,bty,0.4695,bth,"Apstiprināt",true,ConfirmDeleteWin, _, _, _, _, _, _, 0x9900FF00) dgsSetFont(buttons[11],"clear") addEventHandler("onDgsMouseClick", buttons[11], function() if source == buttons[11] then triggerServerEvent("vehlib:deleteVehicle", localPlayer, id) closeConfirmDelete() playSuccess() end end) end If required, can provide more parts that could be linked to this bit of code. Link to comment
Addlibs Posted July 11, 2022 Share Posted July 11, 2022 (edited) The reason one of the copies don't work is because you check if the click event's source is the element in the table buttons and override the values in that table when creating a duplicate copy. If you want both windows to work properly, you should avoid the if source == [some element] then and instead add a false argument after the handler function in addEventHandler. For example addEventHandler("onDgsMouseClick", buttons[11], function() triggerServerEvent("vehlib:deleteVehicle", localPlayer, id) closeConfirmDelete() playSuccess() end, false) That false means the function should not be called for any element other than the element the event is bound to, button[11] at the time the handler was attached; the binding does not change if you later change what buttons[11] references. Edited July 11, 2022 by Addlibs 1 Link to comment
Kilometrs Posted July 11, 2022 Author Share Posted July 11, 2022 11 minutes ago, Addlibs said: The reason one of the copies don't work is because you check if the click event's source is the element in the table buttons and override the values in that table when creating a duplicate copy. If you want both windows to work properly, you should avoid the if source == [some element] then and instead add a false argument after the handler function in addEventHandler. For example addEventHandler("onDgsMouseClick", buttons[11], function() triggerServerEvent("vehlib:deleteVehicle", localPlayer, id) closeConfirmDelete() playSuccess() end, false) That false means the function should not be called for any element other than the element the event is bound to, button[11] at the time the handler was attached; the binding does not change if you later change what buttons[11] references. Thank you for you answer, I think I understood the idea, but in my case, I need to get rid of the duplicate window, so there is only one. Link to comment
Addlibs Posted July 11, 2022 Share Posted July 11, 2022 In that case, you should double check you're not calling showConfirmDelete twice; you can either inspect / show your code for that, or you could add an outputDebugString call at the beginning of the function to see how many times its output. You could use outputDebugString(debug.traceback()) to get information on where exactly the function was called from. If it's being called from a function that handles an event, perhaps the event is triggered multiple times, once per player, perhaps. Link to comment
Kilometrs Posted July 11, 2022 Author Share Posted July 11, 2022 14 minutes ago, Addlibs said: In that case, you should double check you're not calling showConfirmDelete twice; you can either inspect / show your code for that, or you could add an outputDebugString call at the beginning of the function to see how many times its output. You could use outputDebugString(debug.traceback()) to get information on where exactly the function was called from. If it's being called from a function that handles an event, perhaps the event is triggered multiple times, once per player, perhaps. I checked already and there is no trace to the function being called twice. This issue also arouse, when I "translated" the code from the original GUI to DGS. The output from the outputDebugString(debug.traceback(ConfirmDeleteWin) me one result when it is placed in the start of function and 2 results when in the end of it. DGSDebug also shows them both as different. What can I do with the ID's I get (how/where do I use them to track down where the window was called from)? Link to comment
Kilometrs Posted July 11, 2022 Author Share Posted July 11, 2022 After some tinkering around, I found out that the issue was caused because the button, supposedly, clicked twice (once on the press and once on the release (?)). Placed in dgsSetEnable( button, false) and the problem vanished. Link to comment
Addlibs Posted July 12, 2022 Share Posted July 12, 2022 (edited) One of the parameters of the dgs mouse click event: Quote state: the state of the mouse button, will be down if the mouse button was pushed, or up if it was released. Please note currently both up and down state are supported, which is different from onClientGUIClick. For only up or down, see onDgsMouseClickUp/onDgsMouseClickDown In other words, the equivalent of onClientGUIClick is onDgsMouseClickUp, not onDgsMouseClick. The latter is indeed triggered for every mouse button activity (for the press and for the release) while the cursor is over the element. CEGUI click is registered when you release the mouse button while over the element, giving the user an option to cancel a misclick by holding the mouse button, dragging the cursor off the element and releasing. Edited July 12, 2022 by Addlibs 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