Skip to content

Modsettings Button stackoverflow if Callback function is not found #8

@Serpens66

Description

@Serpens66

I tried to add a modsetting button to my mod and used this:

{
    "TitleColor": "#11FF99",
    "Data": {
        "Buttons": [
            {
                "ID" : "EnableDisable_Indomitable",
                "Callback": "EnableDisableIndomitable",
                "Enabled": true,
                "HostOnly": true
            }
        ]
    },
    "MenuOrder": [
        {
            "Entries" : [
                "EnableDisable_Indomitable"
            ]
        }
    ]
}

-- and in server lua script:
function EnableDisableIndomitable(enabled)
end

I thought "HostOnly" would make it execute on the server. So in the end for the client the callback funtion was not defined, which resulted in a stackoverflow on hitting the button, Unlimited times this error:

bad argument #2 to 'tonumber' (number expected, got string)
stack traceback:
	[C++ Code]: in function 'tonumber'
	[C++ Code]: in function 'xpcall'
	LeaderLib/Shared/Classes/ModSettings/Data/ButtonData.lua:52: in upvalue 'TryInvokeFunctions'
	LeaderLib/Shared/Classes/ModSettings/Data/ButtonData.lua:58: in upvalue 'TryInvokeFunctions'
	LeaderLib/Shared/Classes/ModSettings/Data/ButtonData.lua:65: in method 'Invoke'
	LeaderLib/Client/UI/ModMenu/ModMenuManager.lua:393: in field 'OnButtonPressed'
	LeaderLib/Client/UI/ModMenu/OptionsSettingsHooks.lua:502: in function <LeaderLib/Client/UI/ModMenu/OptionsSettingsHooks.lua:498>
	[C++ Code]: in function 'xpcall'
	LeaderLib/Client/Classes/UIWrapper.lua:278: in method 'InvokeCallbacks'
	LeaderLib/Client/Classes/UIWrapper.lua:432: in function <LeaderLib/Client/Classes/UIWrapper.lua:419>
	[C++ Code]: in function 'xpcall'
	builtin://Libs/Event.lua:129: in method 'Throw'
	builtin://Libs/Event.lua:184: in function <builtin://Libs/Event.lua:183>
bad argument #1 to 'math.cos' (number expected, got table)
stack traceback:
	[C++ Code]: in function 'math.cos'
	[C++ Code]: in function 'xpcall'
	LeaderLib/Shared/Classes/ModSettings/Data/ButtonData.lua:52: in upvalue 'TryInvokeFunctions'
	LeaderLib/Shared/Classes/ModSettings/Data/ButtonData.lua:58: in upvalue 'TryInvokeFunctions'
	LeaderLib/Shared/Classes/ModSettings/Data/ButtonData.lua:58: in upvalue 'TryInvokeFunctions'
	LeaderLib/Shared/Classes/ModSettings/Data/ButtonData.lua:65: in method 'Invoke'
	LeaderLib/Client/UI/ModMenu/ModMenuManager.lua:393: in field 'OnButtonPressed'
	LeaderLib/Client/UI/ModMenu/OptionsSettingsHooks.lua:502: in function <LeaderLib/Client/UI/ModMenu/OptionsSettingsHooks.lua:498>
	[C++ Code]: in function 'xpcall'
	LeaderLib/Client/Classes/UIWrapper.lua:278: in method 'InvokeCallbacks'
	LeaderLib/Client/Classes/UIWrapper.lua:432: in function <LeaderLib/Client/Classes/UIWrapper.lua:419>
	[C++ Code]: in function 'xpcall'
	builtin://Libs/Event.lua:129: in method 'Throw'
	builtin://Libs/Event.lua:184: in function <builtin://Libs/Event.lua:183>
bad argument #1 to 'math.modf' (number expected, got table)

I now know that I have to define the function for client, but still it should not cause a stackoverflow if no function is defined :D

edit:
I used the "Variables" in another mod where a "Slider" made sense. Now I wanted in fact a checkbox, but this "Flag" system turned me off, so I decided a Button also would be fine. But here the downside is, that is exected for client...
Why not a simple checkbox/button that works like the sliders for server ?!
But still thank you very much for your work :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions