Hi,
first of all excuse me for my english.
I’am new to Lua and Corona.
I want to assign a value of variable (the variable name is we) to MyText.text
I have a button and when I click on it, call the function button1Release ()
when it is called , add 1 to we variable.
correctly the function add 1 to we , but in the function when execute the line
myText.text = we
Corona said:
Runtime error
C:\Users\DF2\Desktop\TestCorona\test02\main.lua:24: attempt to index global ‘myText’ (a nil value)
stack traceback:
C:\Users\DF2\Desktop\TestCorona\test02\main.lua:24: in function ‘_onRelease’
?: in function ‘?’
?: in function <?:677>
?: in function <?:205>
can you help me ? where is the error ?
thank you very much
this is the code:
–
– main.lua
–
local widget = require( “widget” )
– load my backgroud image
local w, h = display.contentWidth, display.contentHeight
local container = display.newContainer( w, h )
container:translate( display.contentCenterX, display.contentCenterY )
local bkgd = display.newImage( container, “fondo.jpg” )
– initialize my variable we
we = 1
– function for button1
local function button1Release ()
we = we + 1
myText.text = we
end
– create button
local button1 = widget.newButton
{
defaultFile = “buttonRed.png”,
label = “Add 1”,
onRelease = button1Release,
}
– create and display MyText object
local myText = display.newText( “1”, 0, 0, native.systemFont, 50 )
myText.x = display.contentCenterX ; myText.y = display.contentCenterY
myText:setFillColor(black)