Event handlers in Simkin are just regular Simkin functions that take one parameter. A GUI::EventArgs struct. The functions you register as event handlers must already be registered with the system (i.e. defined in a message, inventory or conversation script file), otherwise you will need to load some script files before doing any Simkin handled events. To do this you can use the GUI::System::executeScriptFile function in a Simkin script like so:
Calling this function will execute the specified Simkin script file. This means that functions declared within this file will be accessible to the GUI system.
Now let's take a look at that Simkin event handler:
Here we make sure the button text is handled from Simkin when the button is clicked. We use a utility function
which converts the GUI::EventArgs parameter to a GUI::WindowEventArgs object. Converters for the other EventArgs classes are also available.
Let's assume we have created a GUI::PushButton named simkin_powered_button
. We can access this button in a script with the help of the GUI::WindowManager.
Then we just need to use the GUI::Window::subscribeEvent function to connect the event handler to the desired event, in this example the Clicked
event:
or condensed in one line
An even easier way to bind scripted event handlers to the windows in your XML layouts is to define the event handlers in the XML file itself.
Take a look a this example:
This simple layout creates a push button named simkin_powered_button
and even binds the scripted event handler to it.