Lua and listbox

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

Dalon
Just popping in
Just popping in
Posts: 11
Joined: Wed Sep 15, 2010 13:55

Lua and listbox

Postby Dalon » Sat May 21, 2011 13:17

Hi, it's me again :D

I have another question about CEGUI listboxes in lua. I have the following code...

Code: Select all

function ChatWindow_AddText(text)
    local chatLog = CEGUI.toListbox(wndMgr:getWindow("ChatLog"))    -- I use this as a global variable but just to let you know how I initialise that variable in lua is declare it in the function as local

    ...

   chatLog:addItem(...)
end


I end up with an error: CEGUI::ScriptException in file Game.cpp(336) : Could not call event function: [string "Scripts/Windows/ChatWindow.lua"]:76: attempt to call method 'addItem' (a nil value)

Also I would like to know, what to give as parameter. I know, in cpp I should give a pointer to an instance of for example a CEGUI::ListboxTextItem. I tried this in Lua...

Code: Select all

chatLog:addItem(CEGUI.ListboxTextItem:new(text))


... and ended up with a message that new is a nil value here :D

User avatar
Kulik
CEGUI Team
Posts: 1382
Joined: Mon Jul 26, 2010 18:47
Location: Czech Republic
Contact:

Re: Lua and listbox

Postby Kulik » Sat May 21, 2011 13:34

Well I would guess that the window you are retrieving is not a Listbox so you can't cast it to a Listbox.

There is a big difference between ItemListbox and Listbox, maybe you have mistaken those?

Dalon
Just popping in
Just popping in
Posts: 11
Joined: Wed Sep 15, 2010 13:55

Re: Lua and listbox

Postby Dalon » Sat May 21, 2011 13:38

Hi,

okay I didn't read correctly and was too quick posting here. You were right... i casted the wrong window object -.-"

And I found these very useful ".pkg" files in the cegui source folder which contain some informations about the classes. So it sais:

/***********************************************************************
ListboxTextItem

The constructor is not exportet, instead a helper function is
available (CEGUI.createListboxTextItem).

I decided to do it like this to avoid any possible memory issues
with allocating from Lua.
***********************************************************************/


But thanks :) Now it works ^^


Return to “Help”

Who is online

Users browsing this forum: No registered users and 12 guests