• 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 1.X+ attempt to call method 'titleCase'

Sparkles

snek
Joined
Mar 1, 2009
Messages
320
Solutions
27
Reaction score
148
Location
Norway, Tromsø
Hi,
Im using TFS 1.3 and transferred my datapack from TFS 1.2.
Im having some errors with the NPC's

This is the error I get for im guessing all NPC's that uses titleCase.

Code:
Lua Script Error: [Npc interface]
data/npc/scripts/Brodrosch.lua
data/npc/scripts/Brodrosch.lua:48: attempt to call method 'titleCase' (a nil value)
stack traceback:
    [C]: in function 'titleCase'
    data/npc/scripts/Brodrosch.lua:48: in function 'addTravelKeyword'
    data/npc/scripts/Brodrosch.lua:53: in main chunk
[Warning - NpcScript::NpcScript] Can not load script: Brodrosch.lua

These are included in my lib files:
Functions.lua
Lua:
function titleCase(str)
    return (str:gsub("^%l", string.upper))
end

And heres my string.lua
Lua:
string.split = function(str, sep)
    local res = {}
    for v in str:gmatch("([^" .. sep .. "]+)") do
        res[#res + 1] = v
    end
    return res
end

string.trim = function(str)
    return str:match'^()%s*$' and '' or str:match'^%s*(.*%S)'
end

string.starts = function(str, substr)
    return string.sub(str, 1, #substr) == substr
end

string.titleCase = function(str)
    return str:gsub("(%a)([%w_']*)", function(first, rest) return first:upper() .. rest:lower() end)
end

This is the NPC lua
Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

function onCreatureAppear(cid)            npcHandler:onCreatureAppear(cid)            end
function onCreatureDisappear(cid)        npcHandler:onCreatureDisappear(cid)            end
function onCreatureSay(cid, type, msg)        npcHandler:onCreatureSay(cid, type, msg)        end
function onThink()        npcHandler:onThink()        end

local voices = { {text = 'Passage to Cormaya! Unforgettable steamboat ride!'} }
npcHandler:addModule(VoiceModule:new(voices))

local function creatureSayCallback(cid, type, msg)

    if not npcHandler:isFocused(cid) then
        return false
    end

    if msgcontains(msg, 'ticket') then
        if Player(cid):getStorageValue(Storage.wagonTicket) >= os.time() then
            npcHandler:say('Your weekly ticket is still valid. Would be a waste of money to purchase a second one', cid)
            return true
        end

        npcHandler:say('Do you want to purchase a weekly ticket for the ore wagons? With it you can travel freely and swiftly through Kazordoon for one week. 250 gold only. Deal?', cid)
        npcHandler.topic[cid] = 1
    elseif msgcontains(msg, 'yes') and npcHandler.topic[cid] > 0 then
        local player = Player(cid)
        if npcHandler.topic[cid] == 1 then
            if not player:removeMoney(250) then
                npcHandler:say('You don\'t have enough money.', cid)
                npcHandler.topic[cid] = 0
                return true
            end

            player:setStorageValue(Storage.wagonTicket, os.time() + 7 * 24 * 60 * 60)
            npcHandler:say('Here is your stamp. It can\'t be transferred to another person and will last one week from now. You\'ll get notified upon using an ore wagon when it isn\'t valid anymore.', cid)
        end
        npcHandler.topic[cid] = 0
    elseif msgcontains(msg, 'no') and npcHandler.topic[cid] > 0 then
        npcHandler:say('No then.', cid)
        npcHandler.topic[cid] = 0
    end
    return true
end

local function addTravelKeyword(keyword, cost, discount, destination, action)
    local travelKeyword = keywordHandler:addKeyword({keyword}, StdModule.say, {npcHandler = npcHandler, text = 'Do you seek a ride to ' .. keyword:titleCase() .. ' for |TRAVELCOST|?', cost = cost, discount = discount})
        travelKeyword:addChildKeyword({'yes'}, StdModule.travel, {npcHandler = npcHandler, premium = true, text = 'Full steam ahead!', cost = cost, discount = discount, destination = destination}, nil, action)
        travelKeyword:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, text = 'We would like to serve you some time.', reset = true})
end

addTravelKeyword('farmine', 210, {'postman', 'new frontier'},
    function(player)
        local destination = Position(33025, 31553, 14)
        if player:getStorageValue(Storage.TheNewFrontier.Mission05) == 7 then --if The New Frontier Quest 'Mission 05: Getting Things Busy' complete then Stage 3
            destination.z = 10
        elseif player:getStorageValue(Storage.TheNewFrontier.Mission03) == 3 then --if The New Frontier Quest 'Mission 03: Strangers in the Night' complete then Stage 2
            destination.z = 12
        end

        return destination
    end
)
addTravelKeyword('cormaya', 160, 'postman', Position(33311, 31989, 15),
    function(player)
        if player:getStorageValue(Storage.postman.Mission01) == 4 then
            player:setStorageValue(Storage.postman.Mission01, 5)
        end
    end
)

keywordHandler:addKeyword({'passage'}, StdModule.say, {npcHandler = npcHandler, text = 'Do you want me take you to {Cormaya} or {Farmine}?'})

npcHandler:setMessage(MESSAGE_GREET, 'Welcome, |PLAYERNAME|! May earth protect you on the rocky grounds. If you need a {passage}, I can help you.')
npcHandler:setMessage(MESSAGE_FAREWELL, 'Good bye.')
npcHandler:setMessage(MESSAGE_WALKAWAY, 'Good bye then.')

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

If needed I can send the NPC libs aswell.
Seems to only show the 'addTravelKeyword' function showing up. I dont know where to look for it :rolleyes:

Anyone got any clues?
 
Your function titleCase() takes an argument (which is string), so instead of
keyword:titleCase()
try
titleCase(keyword)
 
Solution
Back
Top