Jump to content

Why this returns nil?


GTX

Recommended Posts

Hello, I tried to move from SQLite to MySQL, like:

addEvent("onMapStarting", true) 
addEventHandler("onMapStarting", root, 
function(mapInfo, mapOptions, gameOptions) 
g_MapInfo = mapInfo 
mapname2 = g_MapInfo.name 
olddata = executeSQLQuery("SELECT playerName, timeText, playerSerial FROM `race maptimes Freeroam "..mapname2.."`") 
if olddata then 
    for i, v in ipairs">ipairs">ipairs">ipairs">ipairs">ipairs">ipairs(olddata) do 
    Date2 = getRealTime() 
    Date = string.format("%02d/%02d/%02d", Date2.monthday, Date2.month + 1, Date2.year + 1900) 
    outputChatBox("RETURNS: ".. tostring">tostring">tostring">tostring(olddata.playerName) .. ", ".. tostring">tostring">tostring">tostring">tostring(olddata.timeText) ..", ".. tostring">tostring">tostring(olddata.playerSerial) ..".") 
    --mysql_query(connect_mysql, "INSERT INTO `"..mapname.."` (name, Time, Date, Serail, CTag) VALUES ('"..tostring(olddata.playerName).."', '"..tostring(olddata.timeText).."', '"..Date.."', '"..tostring(olddata.playerSerial).."','CLAN')") 
    end 
end 
end) 
  
 

Returns nil

I've no idea why. Do you know?

EDIT:

There's freaky bug in


...



addEvent("onMapStarting", true) 
addEventHandler("onMapStarting", root, 
function(mapInfo, mapOptions, gameOptions) 
g_MapInfo = mapInfo 
mapname2 = g_MapInfo.name 
olddata = executeSQLQuery("SELECT playerName, timeText, playerSerial FROM `race maptimes Freeroam "..mapname2.."`") 
if olddata then 
    for i, v in ipairs(olddata) do 
    Date2 = getRealTime() 
    Date = string.format("%02d/%02d/%02d", Date2.monthday, Date2.month + 1, Date2.year + 1900) 
    outputChatBox("RETURNS: ".. tostring(olddata.playerName) .. ", ".. tostring(olddata.timeText) ..", ".. tostring(olddata.playerSerial) ..".") 
    end 
end 
end) 

Thanks in advance

Edited by Guest
Link to comment

addEvent("onMapStarting", true) 
addEventHandler("onMapStarting", root, 
    function(mapInfo, mapOptions, gameOptions) 
    g_MapInfo = mapInfo 
    mapname2 = g_MapInfo.name 
    olddata = executeSQLQuery("SELECT playerName, timeText, playerSerial FROM `race maptimes Freeroam             "..mapname2.."`") 
        if olddata then 
        for i, v in ipairs(olddata) do 
        Date2 = getRealTime() 
        Date = string.format("%02d/%02d/%02d", Date2.monthday, Date2.month + 1, Date2.year + 1900) 
        outputChatBox("RETURNS: ".. tostring(olddata.playerName) .. ", ".. tostring(olddata.timeText) ..", ".. tostring(olddata.playerSerial) ..".") 
        end 
    end 
end) 

Why don't you test it?

tostring(olddata.playerName), tostring(olddata.timeText), tostring(olddata.playerSerial) return nil

Link to comment

For who don't know:

Correct

olddata = executeSQLQuery [[ SELECT playerName, timeText, playerSerial FROM myTable WHERE myMap = 'race maptimes Freeroam "..mapname2.."' ]] 

Or:

olddata = executeSQLQuery ( "SELECT playerName, timeText, playerSerial FROM myTable WHERE myMap = 'race maptimes Freeroam "..mapname2.."' ") 

Link to comment

Nah, it wasn't that. The problem was:

tostring(olddata.playerName), tostring(olddata.timeText), tostring(olddata.playerSerial)

to:

tostring(v.playerName), tostring(v.timeText), tostring(v.playerSerial)

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...