Jump to content

[HELP] onClientKey with this function already handled


Recommended Posts

Hi, i found this dxlib on the community, i'm working on a weapon shop, when i destroy the dxEditBox, then i reopen, i'm only getting erros.

I tried to fix it myself, and i still don't know whats the problem.

Debugs:

line 19: onClientKey with this function is already handled

line 20: onClientCharacter with this function is already handled.

 

Code:

function dxCreateEdit(x, y, w, h, text, icon, lenght, r, g, b, alpha, mask, postGUI)
    local theEdit = createElement("dxEdit")
    if getn(edit.data) < 1 then
        addEventHandler("onClientCharacter", getRootElement(), addCharacterToEdit)  -- line 19
        addEventHandler("onClientKey", root, backspace)  -- line 20
    end
    edit.data[theEdit] = {x = x, y = y ,w = w, h = h, dt = text, icon = icon, ml = lenght, r = r or 0, g = g or 0,b = b or 0, alpha = alpha or 150, mask = mask or false, postGUI = postGUI or false, text = "" , clicked = false, selectAll = false, enabled = true}
    return theEdit
end



function addCharacterToEdit(character)
    if character == " " then return end
    if string.byte(character) < 32 or string.byte(character) > 127 then return end
    local Edit = getElementsByType("dxEdit")
    for i=1,#Edit do    
        if edit.data[Edit[i]] then
            if edit.data[Edit[i]].clicked == true then
                if edit.data[Edit[i]].selectAll == true then
                    edit.data[Edit[i]].selectAll = false
                    edit.data[Edit[i]].text = ""
                end
                if edit.data[Edit[i]].ml ~= nil then
                    if #edit.data[Edit[i]].text < edit.data[Edit[i]].ml then
                    edit.data[Edit[i]].text = edit.data[Edit[i]].text..character
                    end
                else
                    edit.data[Edit[i]].text = edit.data[Edit[i]].text..character
                end
            end
        end
    end
end

function backspace(key,sm)
    if sm then
        local Edit = getElementsByType("dxEdit")
        for i=1,#Edit do    
            if edit.data[Edit[i]] then
                if edit.data[Edit[i]].clicked == true then
                    if string.len(edit.data[Edit[i]].text) > 0 and key == "backspace" then
                        if edit.data[Edit[i]].selectAll == false then
                            edit.data[Edit[i]].text = string.sub(edit.data[Edit[i]].text,1,string.len(edit.data[Edit[i]].text)-1)
                        else
                            edit.data[Edit[i]].selectAll = false
                            edit.data[Edit[i]].text = ""
                        end
                    elseif getKeyState("lctrl") and key == "a" or getKeyState("rctrl") and key == "a" then
                        edit.data[Edit[i]].selectAll = not edit.data[Edit[i]].selectAll
                    end
                end
            end
        end
    end
end

 

Edited by TheMOG
Link to comment
  • Moderators
function dxCreateEdit(x, y, w, h, text, icon, lenght, r, g, b, alpha, mask, postGUI)
    local theEdit = createElement("dxEdit")
    if getn(edit.data) < 1 then
        removeEventHandler("onClientCharacter", getRootElement(), addCharacterToEdit)  -- line 19
        removeEventHandler("onClientKey", root, backspace)  -- line 20
        addEventHandler("onClientCharacter", getRootElement(), addCharacterToEdit)  -- line 19
        addEventHandler("onClientKey", root, backspace)  -- line 20
    end
    edit.data[theEdit] = {x = x, y = y ,w = w, h = h, dt = text, icon = icon, ml = lenght, r = r or 0, g = g or 0,b = b or 0, alpha = alpha or 150, mask = mask or false, postGUI = postGUI or false, text = "" , clicked = false, selectAll = false, enabled = true}
    return theEdit
end

 

Edited by gpetersz
  • Thanks 1
Link to comment

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...