I dont know what Im doing wrong. I retrieving some data from a SQL database in Android and Im triyng to put in a text box. But emulator give me a RUNTIME ERROR:
Runtime error
C:\Users\drago\Desktop\Forca - Android\main.lua:62: attempt to concatena
te local 'textfield' (a nil value)
stack traceback:
[C]: ?
C:\Users\drago\Desktop\Forca - Android\main.lua:62: in function 'onRelea
se'
What Im doing wrong? I KNOW is something related to types, but I dont know what. This is the code:
[lua] local textbox = native.newTextBox( 0, 300, 200, 50 )
textbox.hasBackground = false
textbox:setTextColor(255,0,255)
for row in db:nrows(“SELECT * FROM hangman”) do
textfield = textfield … row.palavras
end
textbox.text = textfield[/lua]
textfield is a local variable. [import]uid: 9133 topic_id: 6363 reply_id: 306363[/import]
You can use print() to check the terminal to see if you are getting any data. You can test out the textbox by hardcoding a value to textfield and if that works then that tells you that your SQL statement is not deriving the data properly.
Its strange, because if I put this line in code, as:
[lua]for row in db:nrows(“SELECT * FROM hangman”) do
local text = row.palavras
local t = display.newText(text, 20, 70 + (20 * row.id), native.systemFont, 16)
t:setTextColor(255,0,255)
end[/lua]
This works ok.
I tried a new code:
[lua]-- Carrega biblioteca para botoes - User Interface
local ui = require(“ui”)
local tb = native.newTextBox( 0, 0, 400, 400 )
tb.text = “Isso e um teste\nE isso deveria estar em duas linhas. Tambem deve ser possivel ver o scroll”
tb.setTextColor( 0, 0, 255 )
tb.hasBackground = true
tb.size = 16[/lua]
Just that. This should work. But What I see? My text and after few seconds, it simply desapear.
IN this case, you are right. I used colon and everything works fine now. Well…almost
Now I have to understand this: I wrote a simple example like this one:
[lua]local tb = native.newTextBox( 15, 70, 280, 70 )
tb.text = “This is line 1.\nAnd this is line2\nLinha 3\nLinha 4\n”
tb:setTextColor( 0, 0, 255 )
tb.hasBackground = true
tb.size = 16[/lua]
Works fine right now. But the box should be scrollable, isnt ? Here, nothing happen. Text aperar, but the last line, cut in the middle, and I don have scroll. Do you know why?
Thanks for your help.
[import]uid: 9133 topic_id: 6363 reply_id: 22109[/import]