Surface_ButtonPressed
Skip to content
mnscript
Surface_ButtonPressed(MNGuiButton, Player) 

Description ​

Invoked when a Surface UI button is pressed.

Arguments ​

MNGuiButton - The MNGuiButton which was pressed
Player - The Player who pressed the button

Example ​

msc
using Console;
using Event;
using Player;
using Surface;

// Create the application UI

MNGuiFrame frame = Surface.CreateApplicationFrame();
MNGuiPanel pnl = frame.GetPanel();

// Create a button which prints "Hello World!" to the console when pressed

MNGuiButton button = Surface.CreateButton(pnl);
button.SetText("Say Hi");
button.SetTag("HiButton");
button.SetData("Hello World!");

// Make sure to update the UI so the button appears on the screen.
Surface.Update();

// Make the event for when the button is pressed

function OnSurfaceButtonPressed(MNGuiButton button, Player player){
    if(button.GetTag() == "HiButton"){
        string message = button.GetData();

        Console.WriteLine("The button says: "..message);
    }
}

Event.AddListener("Surface_ButtonPressed", "surface_buttons", "OnSurfaceButtonPressed");

while(true){
    Event.Process();
}