New UI library not producing a label

I’m trying to get a label on the scree, set it’s colour and text and then later set it’s text based on a textbox content. I’ve started with this:

local ui = require(“ui”)
local defaultLabel = ui.newLabel( “Default”, 200, 35, native.systemFont, 18 )
defaultLabel:setTextColor( 200, 200, 255, 255 )

But it throws an exception:

attempt to call method ‘setTextColor’ (a nil value)

What am I doing wrong?

Please help!

Thanks,

matt [import]uid: 8271 topic_id: 2663 reply_id: 302663[/import]

ui.newLabel is not the same as display.newText()

ul.newLabel returns an object that has its own functions. You will have to crack open ui.lua to see what function you need to use to change the text color.

[import]uid: 8541 topic_id: 2663 reply_id: 7953[/import]

Hi Matt,

your color values are not given as a table.

Try this:

[lua]defaultLabel:setTextColor( { 200, 200, 255, 255} )[/lua]

Cheers
Michael Hartlef

http://www.whiteskygames.com
http://www.twitter.com/mhartlef [import]uid: 5712 topic_id: 2663 reply_id: 8043[/import]

Thanks guys, but what I’ve got now is:

local ui = require(“ui”)
local defaultLabel = ui.newLabel{ “Default”, 20, 35, native.systemFont, 18 }
defaultLabel:setTextColor( { 200, 200, 255, 255 } )

Looking in the ui.lua file I see:

function newLabel( params )
.
.
.
function t:setTextColor( r, g, b, a )

And when I run my main I get:

/main.lua:6: attempt to call method ‘setTextColor’ (a nil value)
stack traceback:
[C]: in function ‘setTextColor’

Could someone post a sample which puts a label up and colours it, using the new ui.lua, please?

Thanks,

Matt. [import]uid: 8271 topic_id: 2663 reply_id: 8045[/import]

Where did you got that version of the UI library? [import]uid: 5712 topic_id: 2663 reply_id: 8047[/import]

The latest version from the code exchange page. [import]uid: 8271 topic_id: 2663 reply_id: 8062[/import]