• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Problem With Lua

GOD Esteve

New Member
Joined
May 18, 2011
Messages
87
Reaction score
1
I have this function to get a value from my DB

Using TFS 1.0

Code:
function GetInfo()
    for k, i in ipairs({'started','guild','breaker','time'}) do
        local tmp = db.storeQuery("SELECT ".. i .." FROM `tmpwoe` WHERE `id` = '1';")
        resultado[k] = result.getDataInt(tmp, i)
        print(resultado[1])
        result.free(tmp)
    end
end

Thats is the error when i execute this function at my server

attempt to index global `resultado` <a nill value> stack traceback:

The print(resultado[1]) it`s to check the function works but got this erro above.

Please help to solve.

Thank You and Merry Christmas
 
Try something like this:

Code:
function GetInfo(id)
    local query = db.storeQuery('SELECT `started`, `guild`, `breaker`, `time` FROM `tmpwoe` WHERE `id` = ' .. id)
    if not query then
        return nil
    end

    local resultado = {
        [1] = result.getDataInt(query, 'started'),
        [2] = result.getDataInt(query, 'guild'),
        [3] = result.getDataInt(query, 'breaker'),
        [4] = result.getDataInt(query, 'time')
    }

    result.free(query)

    return resultado
end
 
Try something like this:

Code:
function GetInfo(id)
    local query = db.storeQuery('SELECT `started`, `guild`, `breaker`, `time` FROM `tmpwoe` WHERE `id` = ' .. id)
    if not query then
        return nil
    end

    local resultado = {
        [1] = result.getDataInt(query, 'started'),
        [2] = result.getDataInt(query, 'guild'),
        [3] = result.getDataInt(query, 'breaker'),
        [4] = result.getDataInt(query, 'time')
    }

    result.free(query)

    return resultado
end

I try many possibilities with your code but got fail in all ):


This script works

Code:
function GetInfo()
    for k, i in ipairs({'started','guild','breaker','time'}) do
        local tmp = db.storeQuery("SELECT ".. i .." FROM `tmpwoe` WHERE `id` = '1';")
        resultado = result.getDataInt(tmp, i)
        result.free(tmp)
        print(resultado)
    end  
end

But when i try to make a "table" of results got a nill value like i show before,
here is the script

Code:
function GetInfo()
    for k, i in ipairs({'started','guild','breaker','time'}) do
        local tmp = db.storeQuery("SELECT ".. i .." FROM `tmpwoe` WHERE `id` = '1';")
        resultado[k] = result.getDataInt(tmp, i)
        result.free(tmp)
        print(resultado[1])
        print(resultado[2])
        print(resultado[3])
        print(resultado[4])
    end  
end


Thank You and Merry Christmas
 
Code:
    local c = {
            {'started', 'guild', 'breaker', 'time'}, -- data
            'tmpwoe', -- sqltbl
            1 -- sp
        }

    function GetInfo(data, sqltbl, sp)
        local r = {}
        for _, i in ipairs(data) do
            local t = db.storeQuery("SELECT ".. i .." FROM `" .. sqltbl .. "` WHERE `id` >= " .. sp .. ";")
            if t then
                table.insert(r, result.getDataInt(t, i))
                result:free(t)
            end
        end
        return next(r) and r or nil
    end

    local results = GetInfo(c[1], c[2], c[3])

    if results then
        for k, v in ipairs(results) do
            print(k, v)
        end
    end
 
Last edited:
Code:
    local c = {
            {'started', 'guild', 'breaker', 'time'}, -- data
            'tmpwoe', -- sqltbl
            1 -- sp
        }

    function GetInfo(data, sqltbl, sp)
        local r = {}
        for _, i in ipairs(data) do
            local t = db.storeQuery("SELECT ".. i .." FROM `" .. sqltbl .. "` WHERE `id` >= " .. sp .. ";")
            if t then
                table.insert(r, result.getDataInt(t, i))
                result:free(t)
            end
        end
        return next(r) and r or nil
    end

    local results = GetInfo(c[1], c[2], c[3])

    if results then
        for k, v in ipairs(results) do
            print(k, v)
        end
    end


Hello Codex,

Well i think you don't understaind what i whant.
The function that i whant to make will take each collum of the database but only of the first line and keep this value of collum to compare with another thing, like that before:

Code:
function GetInfo()
    for k, i in ipairs({'started','guild','breaker','time'}) do
        local tmp = db.storeQuery("SELECT ".. i .." FROM `tmpwoe` WHERE `id` = '1';")
        resultado[k] = result.getDataInt(tmp, i)
        result.free(tmp)
        print(resultado[1])
        print(resultado[2])
        print(resultado[3])
        print(resultado[4])
    end
end

And after will have something like that

Code:
When use something
GetInfo()
if resultado[2] == getplayerguild(cid) then
print(test)
end
 
Last edited:
Well I want you to learn lua, I won't write it for you, because you aren't even trying.

Codex,

Really sad that u say that thing that i don`t try, but it`s your opnion.

This part that i am asking for help it`s 1% of the script that i am making because i`m try to make a new WOE script for TFS 1.0 for my hands, and the last part of script it`s that function, i have a solution that it`s make 1 function for each collum of DB (It`s working) but i shoud like something more clean, it`s that i whant help, and not for make the script for me.
 
Back
Top