Jump to content

setRadioChannel(0) causes C Stack overflow


Recommended Posts

So im experienting with MTA and Lua and noticed that setRadioChannel(0) didnt work for me at first so i added it in the onClientPlayerRadioSwitch event which works but causes a C Stack Overflow.

addEventHandler("onClientPlayerRadioSwitch",getRootElement(),function()  
  
    local vehicle = getPedOccupiedVehicle(localPlayer) 
    if(vehicle) then 
        if(getElementModel(vehicle) == 432) then 
            setRadioChannel(0) 
            cancelEvent() 
        end 
    end 
     
end) 

Edit it seems it doesnt matter which radio number you enter and it doesnt matter if you cancel the event or not

Link to comment
addEventHandler("onClientPlayerRadioSwitch", root, 
function() 
    local vehicle = getPedOccupiedVehicle(localPlayer) 
    if (vehicle) then 
        if (getElementModel(vehicle) == 432) then 
            if getRadioChannel() ~= 0 then 
                setRadioChannel(0) 
                cancelEvent() 
            end 
        end 
    end 
end) 

  • Thanks 1
Link to comment
  • Administrators
addEventHandler("onClientPlayerRadioSwitch", root, 
function() 
    local vehicle = getPedOccupiedVehicle(localPlayer) 
    if (vehicle) then 
        if (getElementModel(vehicle) == 432) then 
            if getRadioChannel() ~= 0 then 
                setRadioChannel(0) 
                cancelEvent() 
            end 
        end 
    end 
end) 

Should fix it perfectly.

Link to comment
Well stack overflow is a function that call another function which call the first function this called a trail function You should visit lua user wiki to see how to fix it !

Not necessarily caused by infinite recursion, but in this case that's more or less it indeed.

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