Page 1 of 1
How to create a button via lua script?
Posted: Mon Jul 30, 2007 11:27
by rickning
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?
Posted: Mon Jul 30, 2007 11:49
by scriptkid
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.
Posted: Tue Jul 31, 2007 05:24
by rickning
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.
Posted: Tue Jul 31, 2007 07:34
by scriptkid
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.
Posted: Wed Aug 01, 2007 03:23
by rickning
Unfortunatly, it failed also.
So, I used another method:
Code: Select all
button:setProperty("UnifiedAreaRect", item[3])
It works, though it's inconvenient.
: D
Posted: Mon Aug 06, 2007 20:43
by Bagheera
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")