Corona sdk,功能运行错误吗?

时间:2013-03-08 12:27:37

标签: function windows-8 lua corona lua-table

我正在尝试将一些数据保存到表中。我从数据库中获取数据,它可以正常工作。 我的问题是数据没有保存在表格中。它是一个像table = {}的lua表,而不是数据库表。

也许它已保存,但看起来打印在保存之前完成,即使我之后再打电话。事实上,我的网络请求似乎是在我的程序中最后完成的,即使我先调用它。

我真的很想知道这个的原因。有任何想法吗?

以下是代码:

---TESTING!

print("Begin teting!")

--hej = require ( "test2" )

local navTable = {
    Eng_Spd = 0,
    Spd_Set = 0
}

local changeTab = function()
    navTable.Eng_Spd = 2
end

printNavTable = function()
    print("navTable innehåller: ")
    print(navTable.Eng_Spd)
    print(navTable.Spd_Set)
end 


require "sqlite3"
local myNewData 
local json = require ("json")
local decodedData



local SaveData2 = function()
    local i = 1
    local counter = 1
    local index = "livedata"..counter
    local navValue = decodedData[index]
    print(navValue)

    while (navValue ~=nil) do
        --tablefill ="INSERT INTO navaltable VALUES (NULL,'" .. navValue[1] .. "','" .. navValue[3] .."','" .. navValue[4] .."','" .. navValue[5] .."','" .. navValue[6] .."');"
        --print(tablefill)
        --db:exec(tablefill)
        if     navValue[3] == "Eng Spd" then navTable.Eng_Spd = navValue[4]
        elseif navValue[3] == "Spd Set" then navTable.Spd_Set = navValue[4]     
        else print("blah")
        end
        print(navTable.Eng_Spd)
        print(navTable.Spd_Set)
        counter=counter+1
            index = "livedata"..counter
                navValue = decodedData[index]           

    end 
end

local function networkListener( event )
    if (event.isError) then
            print("Network error!")
    else
            myNewData = event.response
            print("From server: "..myNewData)
            decodedData = (json.decode(myNewData))
    SaveData2()
    --db:exec("DROP TABLE IN EXISTS navaltable")
    end
end

--function uppdateNavalTable()
    network.request( "http://127.0.0.1/firstMidle.php", "GET", networkListener )

--end
changeTab()
printNavTable()
--uppdateNavalTable()
printNavTable()

print("Done!")

这是输出:

Copyright (C) 2009-2012  C o r o n a   L a b s   I n c .
        Version: 2.0.0
        Build: 2012.971
Begin teting!
navTable innehåller:
2
0
navTable innehåller:
2
0
Done!
From server: {"livedata1":["1","0","Eng Spd","30","0","2013-03-15 11:35:48"],"li
vedata2":["1","1","Spd Set","13","0","2013-03-15 11:35:37"]}
table: 008B5018
30
0
30
13

顺便说一下,navTableinnehÃ¥ller表示navTable包含。

1 个答案:

答案 0 :(得分:1)

答案是网络侦听器与其余代码并行运行。