How to create a button via lua script?

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

rickning
Just popping in
Just popping in
Posts: 3
Joined: Thu Jul 12, 2007 02:10

How to create a button via lua script?

Postby rickning » Mon Jul 30, 2007 11:27

Here's my code:
local button = winMgr:createWindow("TaharezLook/Button", btName)
button:setText(item[1])
button:setSize( CEGUI.Size:new_local(0.5,0.1) )
button:setPosition(CEGUI.Point:new_local(0.1, 0.2))
MainBar:addChildWindow(button)

when it runs, an exception dialog pops up.

After I traced lua_CEGUI.cpp, I found it's caused by type check function.
new_local() returns a non-const user type, while setSize() and setPostion() requires a const one.

How can I solve this problem?

User avatar
scriptkid
Home away from home
Home away from home
Posts: 1178
Joined: Wed Jan 12, 2005 12:06
Location: The Hague, The Netherlands
Contact:

Postby scriptkid » Mon Jul 30, 2007 11:49

Hi and welcome :)

You should be able to call without the 'new_local' part:

Code: Select all

button:setSize( CEGUI.Size(0.5,0.1) )
button:setPosition(CEGUI.Point(0.1, 0.2))


HTH.

rickning
Just popping in
Just popping in
Posts: 3
Joined: Thu Jul 12, 2007 02:10

Postby rickning » Tue Jul 31, 2007 05:24

Thank you, scriptkid.
I tried your code, but it still doesn't work. same error as mine :(


...
So be it, I use release build to avoid type checking.

User avatar
scriptkid
Home away from home
Home away from home
Posts: 1178
Joined: Wed Jan 12, 2005 12:06
Location: The Hague, The Netherlands
Contact:

Postby scriptkid » Tue Jul 31, 2007 07:34

Wait i think i see. SetSize and SetPosition take a UVector2. Can you try this:

Code: Select all

button::setSize(CEGUI.UVector2(CEGUI.UDim(0.5,0.0), CEGUI.UDim(0.1,0.0)));
button::setPosition(CEGUI.UVector2(CEGUI.UDim(0.1,0.0), CEGUI.UDim(0.2,0.0)));

?

Good luck.

rickning
Just popping in
Just popping in
Posts: 3
Joined: Thu Jul 12, 2007 02:10

Postby rickning » Wed Aug 01, 2007 03:23

Unfortunatly, it failed also.

So, I used another method:

Code: Select all

button:setProperty("UnifiedAreaRect", item[3])


It works, though it's inconvenient.

: D

Bagheera
Just popping in
Just popping in
Posts: 9
Joined: Tue Apr 03, 2007 22:03

Postby Bagheera » Mon Aug 06, 2007 20:43

This is working code in my game, using CEGUI 0.5 and Lua 5.1

Code: Select all

function buttonClicked(eventArgs)
   local we = CEGUI.toWindowEventArgs(eventArgs)
   gSceneMgr:getSceneNode("Turret Marker.node"):flipVisibility(true)
end

local winMgr = CEGUI.WindowManager:getSingleton()
local system = CEGUI.System:getSingleton()
local GameGUI = winMgr:getWindow("GameGUI/Window")

local button = CEGUI.toPushButton(winMgr:createWindow("WindowsLook/Button", "GameGUI/Window/T1"))
GameGUI:addChildWindow(button)
button:setSize(CEGUI.UVector2(CEGUI.UDim(0.3, 0), CEGUI.UDim(0.3, 0)))
button:setPosition(CEGUI.UVector2(CEGUI.UDim(0.01, 0), CEGUI.UDim(0.21, 0)))
button:setAlwaysOnTop(true)
button:setText("Turret 1")
button:subscribeEvent("Clicked", "buttonClicked")


Return to “Help”

Who is online

Users browsing this forum: No registered users and 9 guests