• 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!

Solved "attempt to compare number with boolean"

raf

Active Member
Joined
Jan 10, 2011
Messages
261
Reaction score
38
Location
Warsaw, PL
I know what this thread title means :p but i just can't see in script what's wrong.

PHP:
function Player:getLoyaltyDescription(thing)
    local check = db.storeQuery("SELECT `total_premium_points` FROM `accounts` WHERE `id` = " .. db.escapeString(thing:getGuid()))


    local loyaltyTitle = ""
    if ((check >= 0) and (check < 50)) then -- Line 593 that shows up in error.
        loyaltyTitle = "Citizen"
    elseif ((check >= 50) and (check < 100)) then
        loyaltyTitle = "Scout"
    elseif ((check >= 100) and (check < 200)) then
        loyaltyTitle = "Sentinel"
    elseif ((check >= 200) and (check < 400)) then
        loyaltyTitle = "Steward"
    elseif ((check >= 400) and (check < 1000)) then
        loyaltyTitle = "Warden"
    elseif ((check >= 1000) and (check < 2000)) then
        loyaltyTitle = "Squire"
    elseif ((check >= 2000) and (check < 3000)) then
        loyaltyTitle = "Warrior"
    elseif ((check >= 3000) and (check < 4000)) then
        loyaltyTitle = "Keeper"
    elseif ((check >= 4000) and (check < 5000)) then
        loyaltyTitle = "Guardian"
    elseif ((check >= 5000) and (check < 999999999)) then
        loyaltyTitle = "Sage"
    end

    local descr = ""
    if self == thing then
        descr = descr .. " You are "
    elseif thing:getSex() == PLAYERSEX_FEMALE then
        descr = descr .. " She is "
    else
        descr = descr .. " He is "
    end
    descr = descr .. loyaltyTitle .. ' of Legendera.'
    return descr
end


This is the error i get

PHP:
Lua Script Error: [Event Interface]
data/events/scripts/player.lua:Player@onLook
data/global.lua:593: attempt to compare number with boolean
stack traceback:
        [C]: ?
        data/global.lua:593: in function 'getLoyaltyDescription'
        data/events/scripts/player.lua:18: in function <data/events/scripts/player.lua:13>

Could you explain how is it trying to compare number with boolean ?
 
Last edited:
You need to use result.getNumber/getString to get the information from the column. db.escapeString shouldn't be used on numeric values, and accountId should be used instead of playerId.

Code:
local loyaltyTitles = {
    [{0, 50}] = "Citizen",
    [{50, 100}] = "Scout",
    [{100, 200}] = "Sentinel",
    [{200, 400}] = "Steward",
    [{400, 1000}] = "Warden",
    [{1000, 2000}] = "Squire",
    [{2000, 3000}] = "Warrior",
    [{3000, 4000}] = "Keeper",
    [{4000, 5000}] = "Guardian",
    [{5000, 999999999}] = "Sage"
}

function Player:getLoyaltyDescription(thing)
    local description = string.format("%s", thing ~= self and (thing:getSex() == PLAYERSEX_FEMALE and "She is" or "He is") or "You are")
    local resultId = db.storeQuery("SELECT `total_premium_points` FROM `accounts` WHERE `id` = " .. thing:getAccountId())
    if resultId ~= false then
        local loyaltyPoints = result.getNumber(resultId, "total_premium_points")
        result.free(resultId)

        for points, title in pairs(loyaltyTitles) do
            if loyaltyPoints >= points[1] and loyaltyPoints < points[2] then
                description = string.format("%s %s of Legendera.", description, title)
                break
            end
        end
    end

    return description
end
 
You need to use result.getNumber/getString to get the information from the column. db.escapeString shouldn't be used on numeric values, and accountId should be used instead of playerId.

Code:
local loyaltyTitles = {
    [{0, 50}] = "Citizen",
    [{50, 100}] = "Scout",
    [{100, 200}] = "Sentinel",
    [{200, 400}] = "Steward",
    [{400, 1000}] = "Warden",
    [{1000, 2000}] = "Squire",
    [{2000, 3000}] = "Warrior",
    [{3000, 4000}] = "Keeper",
    [{4000, 5000}] = "Guardian",
    [{5000, 999999999}] = "Sage"
}

function Player:getLoyaltyDescription(thing)
    local description = string.format("%s", thing ~= self and (thing:getSex() == PLAYERSEX_FEMALE and "She is" or "He is") or "You are")
    local resultId = db.storeQuery("SELECT `total_premium_points` FROM `accounts` WHERE `id` = " .. thing:getAccountId())
    if resultId ~= false then
        local loyaltyPoints = result.getNumber(resultId, "total_premium_points")
        result.free(resultId)

        for points, title in pairs(loyaltyTitles) do
            if loyaltyPoints >= points[1] and loyaltyPoints < points[2] then
                description = string.format("%s %s of Legendera.", description, title)
                break
            end
        end
    end

    return description
end
THat's hell of a remake :D But that's good, i probably can learn stuff from this thread now. I guess i forgot to include info that i'm using TFS 1.0, and this one probably doesn't contain getNumber function:

PHP:
Lua Script Error: [Event Interface]
data/events/scripts/player.lua:Player@onLook
data/global.lua:605: attempt to call field 'getNumber' (a nil value)
stack traceback:
        [C]: in function 'getNumber'
        data/global.lua:605: in function 'getLoyaltyDescription'
        data/events/scripts/player.lua:18: in function <data/events/scripts/player.lua:13>
 
I guess i forgot to include info that i'm using TFS 1.0, and this one probably doesn't contain getNumber function:
Alright, don't forget to mention it next time! Replace getNumber with getDataInt.
 
Back
Top