CuiButton - Cannot run command when clicked.Solved

I can't seem to get a command to run when a button is pressed.
I can make it close the UI with `Close = FormCompMain` but I can't figure out why the command won't run. The command runs fine when manually called.

Does anyone know how I can resolve this?

private string FormCompMain = "form-coomponent-main";

private void OpenForm(BasePlayer player)
{
  var container = new CuiElementContainer();

  container.Add(new CuiPanel
  {
    CursorEnabled = true,
    Image =
            {
                Color = "0 0 0 0"
            },

    RectTransform =
            {
                AnchorMin = "0 0",
                AnchorMax = "1 1"
            },
  }, "Overlay", FormCompMain);

  container.Add(new CuiButton
  {
    RectTransform =
            {
                AnchorMin = "0.3 0.3",
                AnchorMax = "0.7 0.4"
            },
    Button =
            {
                Color = "0.8 0.8 0.8 1",
                Command = "mycommand"
            },
    Text =
            {
                Text = "Text",
                Color = "0 0 0 1",
                FontSize = 20,
                Align = TextAnchor.MiddleCenter
            }
  }, FormCompMain);

  CuiHelper.DestroyUi(player, FormCompMain);
  CuiHelper.AddUi(player, container);
}

[Command("mycommand")]
public void mycommand(BasePlayer player, string label, string[] args)
{
  // Do stuff
  CuiHelper.DestroyUi(player, FormCompMain);
}​

Is it a console command or chat?

I'm pretty sure "mycommand" needs to be a private method and use IPlayer instead of BasePlayer.

wXLxOgFUEnSjh1r.png 0x89A

I'm pretty sure "mycommand" needs to be a private method and use IPlayer instead of BasePlayer.

I didn't even see the code on mobile, but that could be the case.

 

The Command attribute also requires an IPlayer, otherwise ConsoleCommand attribute with a ConsoleSystem.Arg argument

I abandoned my old project and started again and now everything is working.
I'm still not completely sure why it wasn't working before but oh well.

XUzp4wYTXMV33um.png BlueBeka

I abandoned my old project and started again and now everything is working.
I'm still not completely sure why it wasn't working before but oh well.

The reason the above wouldn't work is what misticos mentioned; the command not being registered.
Locked automatically