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

TFS 0.X how to deal with returns in LUA?

caquinha

Member
Joined
Aug 8, 2016
Messages
248
Solutions
1
Reaction score
24
how to deal with returns in LUA?

i tried to create some global functions like:

data/lib/usual.lua
Code:
function getBaseVocation(cid)
    local voc = getPlayerVocation(cid)
    print("1 data/lib/common.lua voc: " .. voc)
    if voc == 1 or voc == 4 or voc == 5 or voc == 6 or voc == 7 then
        return 1
    elseif voc == 2 or voc == 8 or voc == 9 or voc == 10 then
        return 2
    elseif voc == 3 or voc == 11 or voc == 12 or voc == 13 or voc == 14 or voc == 15 or voc == 16 or voc == 17 then
        return 3
    elseif voc == 0 then
        return 0
    end
end

action
Code:
function onUse(cid, item, frompos, item2, topos)
            print("[action] voc -> " .. getPlayerVocation(cid))
            print("[action] baseVocation -> " .. getBaseVocation(cid))
end

its printing
Code:
[action] voc -> 3
[action] baseVocation -> 268541257

why?
 
Last edited:
Because it returns true? Function is fine even tho it should not have else return, if it was for example C++, you would get error upon compilation.
Lua:
function isWarrior(cid)
    local voc = getPlayerVocation(cid)
    print("voc: " .. voc)
    if voc == 1 or voc == 4 or voc == 5 or voc == 6 or voc == 7 then
        return true
    end
    return false
end

Make sure you are not looking at old print and you don't have this function duplicated with different if.
 

Similar threads

Back
Top