newText Question

All-

Is it possible to put the elements of a table into the newText function?

Thank you all for your help,

Chris [import]uid: 37840 topic_id: 6792 reply_id: 306792[/import]

I would actually like to know this one too. I’ve looked all around the site for it, but can’t find anything on it.

Whenever I try to put a table into the display.newText function, it gives me an error that it expected a string. I can pass something like t[1] to get the first element out of table “t”. But I can’t pass anything else.

Any help would be appreciated. Do I have to create a loop that inserts every element from the table into the display.newText function? [import]uid: 14084 topic_id: 6792 reply_id: 23912[/import]

If the contents are simple, like numbers and strings, use table.concat(myTable, myDelimiterString).

Otherwise there are many table dumping routines out there. [import]uid: 3953 topic_id: 6792 reply_id: 23994[/import]

Hi,

display.newText is a one line text object. It does not support multiline text tables. In the code section is at least one sample that describes the usage of newText to output multiple lines.
Cheers
Michael

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

Awesome. Thanks. With table.concat(myTable, myDelimiterString), is there a way to make each letter available to a touch event?

What I mean is, I have a word “corona” that I’ve split each letter up into a table. So my table is named “word” and has each letter taking up one value in the table. I want to see if there is any way to display all of those letters on the screen to the user, and have a touch event on each of those letters in that table.

I don’t know if that makes sense. Pretty much, I want each letter of a word to have a touch event. Know of any good way to do that? Could I do that with the table.concat method?

Thanks,
–Matt Royer [import]uid: 14084 topic_id: 6792 reply_id: 24070[/import]

Concat just creates a string. What you do with it then is up to you :).

If you want the letters interactive, make them separate display objects and attach a touch handler. [import]uid: 3953 topic_id: 6792 reply_id: 24081[/import]

Cool. Thanks Mark.

Could you give me an example of how to make each letter in a table a display object?

I have the following code for the table listener, but I don’t know how to display it to the page with each letter being a separate display object:

[lua]local letter = {}
for w in string.gmatch(currentWord, “%a”) do
letter[#letter+1] = w
end

function letter:touch(e)
if(e.phase == “ended”) then
letter = nextLetter
end
end
letter:addEventListener(“touch”, letter)[/lua]

I don’t even know how to display it to the page itself because I can’t do:

local displayWord = display.newText(letter, 25,25,nil,25)

I can’t put the table in the newText object… Unless you know a way?

Thanks again for all your help Mark,

–Matt [import]uid: 14084 topic_id: 6792 reply_id: 25507[/import]