Results 1 to 6 of 6

Thread: weird issue with addEventHandler

  1. #1
    Join Date
    Mar 2005
    Posts
    726

    Default weird issue with addEventHandler

    I am not sure what is going on with the addEventHandler I am using but each time an event comes it that matches it multiplies by 2 to the point that it repeated the code 40times any ideas here is my code.

    Code:
    handlerId, err = gir.addEventHandler( ".*", 23, 65000, function( eventString ,eventDevice, keyMod, payloads, captures )
    Thanks,
    Yonu

  2. #2
    Join Date
    Jan 1998
    Location
    Jupiter, FL
    Posts
    13,553

    Default

    can you post the full code? It sounds like you are re-adding the eventhandler on each event. Just add it once. (maybe add a print statement so you can track 'adds').
    Ron
    No support through PM

  3. #3
    Join Date
    Mar 2005
    Posts
    726

    Default

    Here is the full code I have tried it 2 different way witht he end) where is is and with it and the very end of the code also if you use starting as a reference it increases by 2 every run

    Code:
    local tostring = tostring
    handlerId, err = gir.addEventHandler( "Media", 23, 65000, function( eventString ,eventDevice, keyMod, payloads, captures )
    print("starting")
        --[[print("Event: ", eventString, eventDevice, keyMod)
        --table.print(payloads)
        --print(payloads[1])]]--
    end)
       
    if eventString == "Media" then
    rawspc = payloads[1]   
    --print (rawspc) 
    --[[linespc = (string.gsub(rawspc, "%.", "%\n"))
    _, _, pwrstate, pwrpercentage = string.find(rawpwr, "state:%s(.-)%spercentage:%s(.%d%d)")
    print("state ", pwrstate)
    print("percent ",pwrpercentage)]]--
    else
    print ("spc")
    end
    
    if eventString == "Mediapwr" then
    print("bat")
    rawpwr = payloads[1]   
    print (rawpwr) 
    --print(string.gsub(rawpwr, "%.", "%\n"))
    --linepwr = string.gsub(rawpwr, "%.", "%\n")
    
    _, _, pwrstate, pwrpercentage = string.find(rawpwr, "state:%s(.-)%spercentage:%s(.%d%d)")
    print("state ", pwrstate)
    print("percent ",pwrpercentage)
    deviceManager.requestControlValueChange( 165, pwrstate, "lua")
    deviceManager.requestControlValueChange( 166, pwrpercentage, "lua")
    
    --[[ test control anme
    if control then
    		--deviceManager.requestControlValueChange( 165,pwrstate, "lua")
            print("yes")
    	else
    --		local v = "0"
    		--deviceManager.requestControlValueChange( control,"0" , "lua")
            print("no")
    end
    --]]
    end
    Thanks,
    Yonu

  4. #4
    Join Date
    Mar 2005
    Posts
    726

    Default

    The problem is fixed after I thought about what you said about adding a print statement so I looked at where I had my print statements for testing and they were reprinting like crazy but the rest of the script wasn't rerunning.

    Thanks,
    Yonu

  5. #5
    Join Date
    Jan 1998
    Location
    Jupiter, FL
    Posts
    13,553

    Default

    Excellent!! Nice work. print is your friend
    Ron
    No support through PM

  6. #6
    Join Date
    Mar 2005
    Posts
    726

    Default

    except when they are in the wrong places lol

    Yonu

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •