Corona sdk局部变量未获取场景内的设置数据



我是corona的新手,我正试图在选项卡场景中创建一个gps。我创建了一个本地变量loc,它是位置数据字符串将被放置在的位置

local loc = "Loading" -- as initial value
then a location handler put a new value to it
local function locationHandler( event )
...
    loc = "the gps location"
end
function scene:createScene( event )
    local group = self.view
    -- create a white background to fill screen
    local bg = display.newRect( 0, 0, display.contentWidth, display.contentHeight )
    bg:setFillColor( 255 )  -- white
    local title = display.newRetinaText(loc, 0, 0, native.systemFont, 20 )
    -- this is where the loc is placed in the title
    title:setTextColor( 0 ) -- black
    title:setReferencePoint( display.CenterReferencePoint )
    title.x = display.contentWidth * 0.5
    title.y = 170
end

问题是loc在模拟器中运行时仍然包含"Loading"。我已经检查过了,gps工作正常,应该放在loc变量中的文本已经准备好进入内部处理程序,使用logcat进行检查。

我做错了什么?

感谢

此代码:

local title = display.newRetinaText(loc, 0, 0, native.systemFont, 20 )

生成loc变量的副本并将其传递给RetinaText。要更改标题,请使用

title.text = "new text"

考虑这个例子:

local test = "1"
local function change( test )
    test = "2"
end
print(test)
change(test)
print(test)

它打印:

1
1

最新更新