synthmilieu Posted May 18, 2015 Share Posted May 18, 2015 I'm trying to add a sword item to a character I'm making for their starting item that functions similarly to Lucy in the sense that it has dialgue. But I keep getting errors claiming that its say function is nil even after I defined the strings in the mainmod.lua. My dialogue code is basically just a mismatched version of Lucy's.-- KAJ: TODO MP_TALK - there's a lot of Say() in here-- KAJ: TODO Strings assume woodielocal SentientAxe = Class(function(self, inst) self.inst = inst self.time_to_convo = 10 self.inst:ListenForEvent("equipped", function(_, data) self:OnEquipped(data.owner) end) self.inst:ListenForEvent("onpickup", function(_, data) self:OnPickedUp(data.owner) end) local dt = 5 self.inst:DoPeriodicTask(dt, function() self:OnUpdate(dt) end) self.warnlevel = 0 self.OnDroppedClosure = function() self:OnDropped() end self.OnFinishedWorkClosure = function(_,data) self:OnFinishedWork(data.target, data.action) endend)function SentientAxe:SetOwner(owner) if owner then if owner ~= self.owner then self.inst:ListenForEvent("ondropped", self.OnDroppedClosure) self.inst:ListenForEvent("finishedwork", self.OnFinishedWorkClosure, owner) end else if self.owner then -- remove owner specific listeners self.inst:RemoveEventCallback("ondropped", self.OnDroppedClosure) self.inst:RemoveEventCallback("finishedwork", self.OnFinishedWorkClosure, self.owner) end end self.owner = ownerendfunction SentientAxe:OnHaunted() local snd = {"dontstarve/characters/woodie/lucy_warn_1", "dontstarve/characters/woodie/lucy_warn_2"} self:Say(STRINGS.ECHO.on_haunted, snd[math.random(#snd)])endfunction SentientAxe:OnPickedUp(owner) self:SetOwner(owner)endfunction SentientAxe:OnFinishedWork(target, action) --self:Say(STRINGS.ECHO.on_chopped) if action == ACTIONS.CHOP and self.inst.components.inventoryitem.owner and self.inst.components.inventoryitem.owner:HasTag("player") and self.inst.components.equippable:IsEquipped() then self:Say(STRINGS.ECHO.on_chopped) end endfunction SentientAxe:OnDropped() assert(self.owner) if self.owner and self.owner.prefab == "elizabeth" then self:Say(STRINGS.ECHO.on_dropped) --end self:SetOwner(nil) endendfunction SentientAxe:OnEquipped(picked_up_by) self:SetOwner(picked_up_by) if picked_up_by:HasTag("player") then if picked_up_by.prefab == "elizabeth" then self:Say(STRINGS.ECHO.on_pickedup) else self:Say(STRINGS.ECHO.other_owner) end endendfunction SentientAxe:OnUpdate(dt) self.time_to_convo = self.time_to_convo - dt if self.time_to_convo <= 0 then self:MakeConversation() endendfunction SentientAxe:MakeConversation() local grand_owner = self.inst.components.inventoryitem:GetGrandOwner() local owner = self.inst.components.inventoryitem.owner local quiplist = nil if owner and owner:HasTag("player") then if self.inst.components.equippable:IsEquipped() and owner.prefab == "elizabeth" and owner.components.beaverness:GetPercent() < .25 then --currently equipped quiplist = STRINGS.ECHO.equipped elseif self.inst.components.equippable:IsEquipped() and owner.prefab == "elizabeth" then elseif self.inst.components.equippable:IsEquipped() then --in player inventory quiplist = STRINGS.ECHO.other_owner end elseif owner == nil then --on the ground quiplist = STRINGS.ECHO.on_ground elseif grand_owner and grand_owner ~= owner and grand_owner:HasTag("player") then --in a backpack quiplist = STRINGS.ECHO.in_container elseif owner and owner.components.container then --in a container quiplist = STRINGS.ECHO.in_container else --owned by someone else quiplist = STRINGS.ECHO.other_owner end if quiplist then self:Say(quiplist) endendreturn SentientAxeam I doing it wrong? Link to comment https://forums.kleientertainment.com/forums/topic/54161-need-help-with-a-custom-item/ Share on other sites More sharing options...
synthmilieu Posted May 19, 2015 Author Share Posted May 19, 2015 Here's my error message if it helps. [string"../mods/Elizabeth/scripts/components/sentie..."]:137: attempt to call method 'Say'(a nil value)LUA ERROR stack traceback: ../mods/Elizabeth/scripts/components/sentientaxe/lua:137 in (method) OnEquiped(Lua)<133-142> ../mods/Elizabeth/scripts/components/sentientaxe/lua:78 in (local) fn (Lua) <78-78> scripts/entityscript.lua:935 in (method) PushEvent (Lua) <929-952> scripts/components/equippable.lua:72 in (method) epuip(Lua) <62-74> scripts/components/inventory.lua:815 in () ? (Lua) <752-829> =tail call):-1 in () (tail) <-1--1> scripts/bufferedaction.lua:22 in (method) Do (Lua) <19-35> Link to comment https://forums.kleientertainment.com/forums/topic/54161-need-help-with-a-custom-item/#findComment-638689 Share on other sites More sharing options...
Blueberrys Posted May 19, 2015 Share Posted May 19, 2015 (edited) @synthmilieu Do you have a function called Say in that script? (copied from sentientaxe.lua)function SentientAxe:Say(list, sound_override) self.sound_override = sound_override self.inst.components.talker:Say(list[math.random(#list)]) self.time_to_convo = math.random(60, 120)end Edited May 19, 2015 by Blueberrys Link to comment https://forums.kleientertainment.com/forums/topic/54161-need-help-with-a-custom-item/#findComment-638694 Share on other sites More sharing options...
synthmilieu Posted May 20, 2015 Author Share Posted May 20, 2015 Welp, I'm an idiot missed a few lines I needed. Link to comment https://forums.kleientertainment.com/forums/topic/54161-need-help-with-a-custom-item/#findComment-639234 Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now