Cannot execute lua function from the ui event

For help with general CEGUI usage:
- Questions about the usage of CEGUI and its features, if not explained in the documentation.
- Problems with the CMAKE configuration or problems occuring during the build process/compilation.
- Errors or unexpected behaviour.

Moderators: CEGUI MVP, CEGUI Team

Herpderp
Just popping in
Just popping in
Posts: 12
Joined: Wed Sep 07, 2011 22:43

Cannot execute lua function from the ui event

Postby Herpderp » Sun Sep 22, 2013 05:01

Hi! I want to execute a lua function by clicking on a button.

First of all here is my log and gui creation code (just to confirm that everything loaded OK)

Code: Select all

22/09/2013 08:02:18 (Std)    ********************************************************************************
22/09/2013 08:02:18 (Std)    * -------- START OF ESSENTIAL SECTION TO BE POSTED ON THE FORUM       -------- *
22/09/2013 08:02:18 (Std)    ********************************************************************************
22/09/2013 08:02:18 (Std)    ---- Version: 0.8.2 (Build: Sep 20 2013 Microsoft Windows MSVC++ 11.0 32 bit) ----
22/09/2013 08:02:18 (Std)    ---- Renderer module is: CEGUI::IrrlichtRenderer - Official Irrlicht based 2nd generation renderer module.  RenderTarget support is enabled. ----
22/09/2013 08:02:18 (Std)    ---- XML Parser module is: CEGUI::TinyXMLParser - Official tinyXML based parser module for CEGUI ----
22/09/2013 08:02:18 (Std)    ---- Image Codec module is: FreeImageCodec - FreeImage based image codec ----
22/09/2013 08:02:18 (Std)    ---- Scripting module is: CEGUI::LuaScriptModule - Official Lua based scripting module for CEGUI ----
22/09/2013 08:02:18 (Std)    ********************************************************************************
22/09/2013 08:02:18 (Std)    * -------- END OF ESSENTIAL SECTION TO BE POSTED ON THE FORUM         -------- *

Code: Select all

GuiRenderer = &CEGUI::IrrlichtRenderer::create( device );
CEGUI::DefaultResourceProvider* rp = new CEGUI::DefaultResourceProvider;
...
CEGUI::LuaScriptModule* script_module = &CEGUI::LuaScriptModule::create();
CEGUI::TinyXMLParser* xml_parser = new CEGUI::TinyXMLParser;
CEGUI::FreeImageImageCodec* image_codec = new CEGUI::FreeImageImageCodec;
CEGUI::System::create( *GuiRenderer, rp, xml_parser, image_codec, script_module, "../datafiles/gui.cfg", "gui.log");


gui.cfg script:

Code: Select all

<?xml version="1.0" ?>
<CEGUIConfig>
<Scripting
    initScript="init_script.lua"
/>
</CEGUIConfig>


init_script.lua contains this function and loads a layout

Code: Select all

function button_clicked(e)
   local logger = CEGUI.Logger:getSingleton()
   logger:logEvent( ">>> It works" )
end

(layout load)

This file (and Lua as well) works since I can see my layout ui and some other events are logged to my log file.

layout:

Code: Select all

...
            <Window type="TaharezLook/Button" name="Button3" >
                <Property name="Area" value="{{0,120},{0,100},{0,216},{0,132}}" />
                <Property name="Text" value="A button" />
                <Event Name="Clicked" Function="button_clicked" />
            </Window>
...

It should call the lua function "button_clicked()" but it does not. Button is clicked (I can see hover/pressdown images) but nothing happens. There is no errors in logfile/console too. Do I need something else?

Herpderp
Just popping in
Just popping in
Posts: 12
Joined: Wed Sep 07, 2011 22:43

Re: Cannot execute lua function from the ui event

Postby Herpderp » Mon Sep 23, 2013 01:25

I've added this to my lua file

Code: Select all

myRoot:getChild("TextDemo/Button2"):subscribeEvent("Clicked", "button_clicked")


Works now. Why didn't it worked with <Event> tag in layout file?

User avatar
mmixLinus
Quite a regular
Quite a regular
Posts: 71
Joined: Fri May 20, 2011 08:46
Location: Lund, Sweden
Contact:

Re: Cannot execute lua function from the ui event

Postby mmixLinus » Wed Sep 25, 2013 21:29

Don't know. Because you had the <Event ...> in Button3, but did subscribeEvent() on Button2? Sorry, just joking :lol: Let us know if you figure it out, and please set the original message's Subject to "[Solved] Cannot..." when you're done.
MMiX.Me 3D Music Player
Galaxy Navigator 3D - 2 million stars (ESA's Gaia satellite)
(YouTube|Facebook)


Return to “Help”

Who is online

Users browsing this forum: No registered users and 12 guests