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?
How to create a button via lua script?
Moderators: CEGUI MVP, CEGUI Team
- scriptkid
- Home away from home
- Posts: 1178
- Joined: Wed Jan 12, 2005 12:06
- Location: The Hague, The Netherlands
- Contact:
Hi and welcome
You should be able to call without the 'new_local' part:
HTH.

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.
- scriptkid
- Home away from home
- Posts: 1178
- Joined: Wed Jan 12, 2005 12:06
- Location: The Hague, The Netherlands
- Contact:
Wait i think i see. SetSize and SetPosition take a UVector2. Can you try this:
?
Good luck.
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.
Unfortunatly, it failed also.
So, I used another method:
It works, though it's inconvenient.
: D
So, I used another method:
Code: Select all
button:setProperty("UnifiedAreaRect", item[3])
It works, though it's inconvenient.
: D
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")
Who is online
Users browsing this forum: No registered users and 21 guests